-
Notifications
You must be signed in to change notification settings - Fork 868
Possibility to provide default values for the entity #117
Conversation
Looks good! Just one small issue — the following test will fail: it('does not overwrite the default', function () {
var article = new Schema('articles', {defaults: {isFavorite: false}}),
input;
input = {
id: 1
};
Object.freeze(input);
normalize({ id: 2, title: 'foo' }, article);
normalize(input, article).should.eql({
result: 1,
entities: {
articles: {
1: {
id: 1,
isFavorite: false
}
}
}
});
}); |
let normalized = {}; | ||
const defaults = schema && schema.getDefaults && schema.getDefaults(); | ||
const schemaAssignEntity = schema && schema.getAssignEntity && schema.getAssignEntity(); | ||
let normalized = isObject(defaults) ? defaults : {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To fix the test I noted, I believe you just need to make a new object that includes the default values:
let normalized = isObject(defaults) ? { ...defaults } : {};
// or
let normalized = isObject(defaults) ? Object.assign({}, defaults) : {};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. My bad (( didn't think about object reference. I'll go with spread, because as I understand Object.assign should be polyfilled.
PR updated |
@paularmstrong ping |
@smashercosmo (sorry, been on holiday) Looks good. I'll mark it to be merged and in the next release. I'd like to hold off on merging for now so that the documentation doesn't add any confusion as to why it's not available yet. |
Any news on this? |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This PR fixes #114.