Skip to content
This repository was archived by the owner on Feb 20, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ export class Block {
this._updateViewValue(binding, bindingType, binding.desc[bindingType]);
} else {
for (var bindingDest in binding.desc[bindingType]) {
this._updateViewValue(binding, bindingType, binding.desc[bindingType][bindingDest], bindingDest);
if (binding.desc[bindingType].hasOwnProperty(bindingDest)) {
this._updateViewValue(binding, bindingType, binding.desc[bindingType][bindingDest], bindingDest);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ViewModel {
var hasChanged = false;

for (var key in data) {
if (key[0] !== '_') {
if (data.hasOwnProperty(key) && key[0] !== '_') {
var oldValue = this[key];
var newValue = data[key];

Expand Down
12 changes: 12 additions & 0 deletions test/View.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,16 @@ describe('View', function () {
});
});

describe('#_getPropTarget', function() {
it('should return an object', function() {
// The any type is there so TypeScript doesn't complain in the for loop
var foo: any = "0";
var view = new View();

for (var p in foo) {
assert.strictEqual(typeof view._getPropTarget(foo[p]), "object");
}
});
});

});
26 changes: 26 additions & 0 deletions test/ViewModel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,30 @@ describe('ViewModel', function () {
});
});

describe('setData()', function() {
it('should set data', function() {
var vm = new ViewModel();
assert.strictEqual(vm['foo'], undefined);
vm.setData({foo: 'hello world'});
assert.strictEqual(vm['foo'], 'hello world');
});

it('should not set data from the prototype', function() {
var vm = new ViewModel();

var ParentClass = function() {
this.foo = 42;
};

var SubClass = function() {
this.bar = 'hello';
};

SubClass.prototype = new ParentClass();

vm.setData(new SubClass());
assert.strictEqual(vm['foo'], undefined);
});
});

});