Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mchlbrnd opened this issue Aug 14, 2017 · 0 comments
Open

Comments

@mchlbrnd
Copy link
Owner

mchlbrnd commented Aug 14, 2017

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant