Skip to content

Commit

Permalink
Observable in model prototype will now be wrapped when it's not an
Browse files Browse the repository at this point in the history
property in models dataItem as expected.

Added tests for it.
  • Loading branch information
Kanaye committed Dec 15, 2016
1 parent e87d5c0 commit 5de343e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/mvc/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ define([
property = properties[key];
if (property) {
this._setPropertyValue(property, dataItem[key]);
} else if (blocks.isObservable(this[key])) {
this[key](dataItem[key]);
} else {
this[key] = dataItem[key];
}
Expand Down
2 changes: 1 addition & 1 deletion src/query/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ define([
if (options.raw) {
blocks.each(blocks.toArray(value), function (val, i) {
values[i] = blocks.isObject(val) ? val : {observables: [], result: val, value: val};
})
});
}

return options.raw ? values : value;
Expand Down
9 changes: 9 additions & 0 deletions test/spec/mvc/property.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ describe('blocks.Application.Property: ', function () {
Product();
});

it('it wraps an value into an observable if it is specified in the constructor', function () {
var TestConstructor = Application.Model({
test: blocks.observable()
});
var testItem = TestConstructor({test: 1});
expect(blocks.isObservable(testItem.test)).toBe(true);
expect(testItem.test()).toBe(1);
});

it('changing Application.Property.Defaults affects the default property options', function () {
Application.Property.Defaults.set('isObservable', false);
var Product = Application.Model({
Expand Down

0 comments on commit 5de343e

Please sign in to comment.