-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Milestone
Description
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:
-
- For static method: how to let the API know normaliza input is an array? As seen in bug: Unable to (de)normalize an array of values #1 the Array type was determined based on input.
-
- 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!