Skip to content

Commit 5de343e

Browse files
committed
Observable in model prototype will now be wrapped when it's not an
property in models dataItem as expected. Added tests for it.
1 parent e87d5c0 commit 5de343e

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/mvc/Model.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ define([
314314
property = properties[key];
315315
if (property) {
316316
this._setPropertyValue(property, dataItem[key]);
317+
} else if (blocks.isObservable(this[key])) {
318+
this[key](dataItem[key]);
317319
} else {
318320
this[key] = dataItem[key];
319321
}

src/query/methods.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ define([
223223
if (options.raw) {
224224
blocks.each(blocks.toArray(value), function (val, i) {
225225
values[i] = blocks.isObject(val) ? val : {observables: [], result: val, value: val};
226-
})
226+
});
227227
}
228228

229229
return options.raw ? values : value;

test/spec/mvc/property.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ describe('blocks.Application.Property: ', function () {
9999
Product();
100100
});
101101

102+
it('it wraps an value into an observable if it is specified in the constructor', function () {
103+
var TestConstructor = Application.Model({
104+
test: blocks.observable()
105+
});
106+
var testItem = TestConstructor({test: 1});
107+
expect(blocks.isObservable(testItem.test)).toBe(true);
108+
expect(testItem.test()).toBe(1);
109+
});
110+
102111
it('changing Application.Property.Defaults affects the default property options', function () {
103112
Application.Property.Defaults.set('isObservable', false);
104113
var Product = Application.Model({

0 commit comments

Comments
 (0)