Skip to content

Commit

Permalink
Changed behavior of not-defined properties to not be wrapped within an
Browse files Browse the repository at this point in the history
observable.

Closes astoilkov#155.
  • Loading branch information
Kanaye committed Dec 3, 2016
1 parent 2082eef commit 0ddd249
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/mvc/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,11 @@ define([

for (key in dataItem) {
property = properties[key];
if (!property) {
property = properties[key] = blocks.extend({}, this._application.Property.Defaults());
property.propertyName = key;
if (property) {
this._setPropertyValue(property, dataItem[key]);
} else {
this[key] = dataItem[key];
}
this._setPropertyValue(property, dataItem[key]);
}
}

Expand Down
7 changes: 6 additions & 1 deletion test/spec/mvc/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
var Application;
var Products;
var Remotes;
var Product;

beforeEach(function () {
Application = blocks.Application();
Expand All @@ -16,7 +17,11 @@
}
});

Products = Application.Collection({
Product = Application.Model({
FirstName: Application.Property()
});

Products = Application.Collection(Product, {
options: {
read: {
url: 'Products'
Expand Down
9 changes: 6 additions & 3 deletions test/spec/mvc/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@
FirstName: 'Antonio'
});

expect(model.id()).toBe(0);
expect(model.FirstName()).toBe('Antonio');
expect(model.id.toBe(0);
expect(model.FirstName.toBe('Antonio');
});

it('default Application.Property creates observable values', function () {
var Product = Application.Model({});
var Product = Application.Model({
id: Application.Property(),
FirstName: Application.Property()
});
Application.start();
var model = Product({
id: 0,
Expand Down
4 changes: 4 additions & 0 deletions test/spec/mvc/property.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ describe('blocks.Application.Property: ', function () {

it('property could define a dependency value', function () {
var Product = Application.Model({
FirstName: Application.Property(),
LastName: Application.Property(),
FullName: Application.Property({
value: function () {
return this.FirstName() + ' ' + this.LastName();
Expand All @@ -322,6 +324,8 @@ describe('blocks.Application.Property: ', function () {

it('property could define a getter/setter', function () {
var Product = Application.Model({
FirstName: Application.Property(),
LastName: Application.Property(),
FullName: Application.Property({
value: {
get: function () {
Expand Down

0 comments on commit 0ddd249

Please sign in to comment.