Skip to content

Add normlize API as static and prototype method to decorated class  #6

@mchlbrnd

Description

@mchlbrnd

Extend the decorated class with the normalize API.

@Entity({key: 'users'})
class User {
  public readonly id: number;
  public age: number;
}

// instantiate a User object (ignore id for now)
const user = new User();
// set age property of instantiated user
user.age = 42;

// normalize through prototype method
const normalizedProtoUser1 = user.normalize();  // internally calls normalizr.normalize(this, typeOfThis);
// ... and with optional arg
const normalizedProtoUser2 = user.normalize({age: 43});

// normalize through static method with required data arg
const normalizedStaticUser = User.normalize({id: 1, age: 42});  

Questions:

    • Would it be nice to have a dedicated method for Array normalization?
// 1) internally determine based on input arg
User.normalize([]);

// 2) specialized method for Array type
User.normalizeArray([]);

Feedback welcome!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions