Generic coercion
class Location {
constructor({ x, y }) {
this.x = x;
this.y = y;
}
}
const User = attributes({
location: Location
})(class User { });
const userOne = new User({
location: new Location({ x: 1, y: 2 })
});
userOne.location; // Location { x: 1, y: 2 } => no coercion was done
const userTwo = new User({
location: { x: 3, y: 4 }
});
userTwo.location; // Location { x: 3, y: 4 } => coerced plain object to LocationLast updated