diff --git a/dist/treacherous.all.js b/dist/treacherous.all.js index 2951ce5..a61cf22 100644 --- a/dist/treacherous.all.js +++ b/dist/treacherous.all.js @@ -7133,17 +7133,17 @@ return /******/ (function(modules) { // webpackBootstrap currentValue = _this.propertyResolver.resolveProperty(_this.model, paramRoute); hasValue = true; } - catch (ex) {} - - if ((currentValue == null || typeof(currentValue) == "undefined") && (anyRulesAreForEach || anyRulesAreSets)) { + catch (ex) { } + if (currentValue == null && (anyRulesAreForEach || anyRulesAreSets)) { if (anyRulesAreForEach) { currentValue = []; } else if (anyRulesAreSets) { currentValue = {}; } - else - { currentValue = null; } + else { + currentValue = null; + } } parameterRules.forEach(function (rule) { var isArray = type_helper_1.TypeHelper.isArrayType(currentValue); @@ -7190,22 +7190,20 @@ return /******/ (function(modules) { // webpackBootstrap return; } var refreshOnNextCycle = false; - console.log("watcher cache", _this.watchCache); _this.watchCache.forEach(function (propertyWatcher) { var currentValue; + var hasChanged = false; try { currentValue = _this.propertyResolver.resolveProperty(_this.model, propertyWatcher.propertyPath); } catch (ex) { } - - if(typeof(currentValue) == "undefined" ) - { currentValue = propertyWatcher.previousValue; } - + if (typeof (currentValue) == "undefined") { + currentValue = propertyWatcher.previousValue; + } if (propertyWatcher.previousValue && propertyWatcher.previousValue.isArray) { var currentLength = currentValue.length || 0; - console.log("has changed?", currentLength != propertyWatcher.previousValue.length); if (currentLength != propertyWatcher.previousValue.length) { - refreshOnNextCycle = true; + hasChanged = true; } } else if (currentValue !== propertyWatcher.previousValue) { @@ -7213,6 +7211,9 @@ return /******/ (function(modules) { // webpackBootstrap setTimeout(function () { _this.onPropertyChanged.publish(propertyChangedArgs); }, 1); propertyWatcher.previousValue = currentValue; } + if (hasChanged) { + refreshOnNextCycle = true; + } }); if (refreshOnNextCycle) { setTimeout(_this.updateAndNotifyDifferences, 1); diff --git a/dist/treacherous.browser.js b/dist/treacherous.browser.js index 3f3e5dd..e3ed4ff 100644 --- a/dist/treacherous.browser.js +++ b/dist/treacherous.browser.js @@ -1232,14 +1232,11 @@ return /******/ (function(modules) { // webpackBootstrap } }); hasValue = false; - currentValue = null; try { currentValue = _this.propertyResolver.resolveProperty(_this.model, paramRoute); hasValue = true; } - catch (ex) { - currentValue = null; - } + catch (ex) { } if (currentValue == null && (anyRulesAreForEach || anyRulesAreSets)) { if (anyRulesAreForEach) { currentValue = []; @@ -1247,6 +1244,9 @@ return /******/ (function(modules) { // webpackBootstrap else if (anyRulesAreSets) { currentValue = {}; } + else { + currentValue = null; + } } parameterRules.forEach(function (rule) { var isArray = type_helper_1.TypeHelper.isArrayType(currentValue); @@ -1293,20 +1293,20 @@ return /******/ (function(modules) { // webpackBootstrap return; } var refreshOnNextCycle = false; - console.log("watcher cache", _this.watchCache); _this.watchCache.forEach(function (propertyWatcher) { var currentValue; + var hasChanged = false; try { currentValue = _this.propertyResolver.resolveProperty(_this.model, propertyWatcher.propertyPath); } - catch (ex) { + catch (ex) { } + if (typeof (currentValue) == "undefined") { currentValue = propertyWatcher.previousValue; } if (propertyWatcher.previousValue && propertyWatcher.previousValue.isArray) { var currentLength = currentValue.length || 0; - console.log("has changed?", currentLength != propertyWatcher.previousValue.length); if (currentLength != propertyWatcher.previousValue.length) { - refreshOnNextCycle = true; + hasChanged = true; } } else if (currentValue !== propertyWatcher.previousValue) { @@ -1314,6 +1314,9 @@ return /******/ (function(modules) { // webpackBootstrap setTimeout(function () { _this.onPropertyChanged.publish(propertyChangedArgs); }, 1); propertyWatcher.previousValue = currentValue; } + if (hasChanged) { + refreshOnNextCycle = true; + } }); if (refreshOnNextCycle) { setTimeout(_this.updateAndNotifyDifferences, 1); diff --git a/dist/treacherous.js b/dist/treacherous.js index c8dd53e..6b77bfb 100644 --- a/dist/treacherous.js +++ b/dist/treacherous.js @@ -1232,14 +1232,11 @@ return /******/ (function(modules) { // webpackBootstrap } }); hasValue = false; - currentValue = null; try { currentValue = _this.propertyResolver.resolveProperty(_this.model, paramRoute); hasValue = true; } - catch (ex) { - currentValue = null; - } + catch (ex) { } if (currentValue == null && (anyRulesAreForEach || anyRulesAreSets)) { if (anyRulesAreForEach) { currentValue = []; @@ -1247,6 +1244,9 @@ return /******/ (function(modules) { // webpackBootstrap else if (anyRulesAreSets) { currentValue = {}; } + else { + currentValue = null; + } } parameterRules.forEach(function (rule) { var isArray = type_helper_1.TypeHelper.isArrayType(currentValue); @@ -1293,20 +1293,20 @@ return /******/ (function(modules) { // webpackBootstrap return; } var refreshOnNextCycle = false; - console.log("watcher cache", _this.watchCache); _this.watchCache.forEach(function (propertyWatcher) { var currentValue; + var hasChanged = false; try { currentValue = _this.propertyResolver.resolveProperty(_this.model, propertyWatcher.propertyPath); } - catch (ex) { + catch (ex) { } + if (typeof (currentValue) == "undefined") { currentValue = propertyWatcher.previousValue; } if (propertyWatcher.previousValue && propertyWatcher.previousValue.isArray) { var currentLength = currentValue.length || 0; - console.log("has changed?", currentLength != propertyWatcher.previousValue.length); if (currentLength != propertyWatcher.previousValue.length) { - refreshOnNextCycle = true; + hasChanged = true; } } else if (currentValue !== propertyWatcher.previousValue) { @@ -1314,6 +1314,9 @@ return /******/ (function(modules) { // webpackBootstrap setTimeout(function () { _this.onPropertyChanged.publish(propertyChangedArgs); }, 1); propertyWatcher.previousValue = currentValue; } + if (hasChanged) { + refreshOnNextCycle = true; + } }); if (refreshOnNextCycle) { setTimeout(_this.updateAndNotifyDifferences, 1); diff --git a/package.json b/package.json index c0267cc..ae957c3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "treacherous", - "version": "0.6.3", + "version": "0.7.0", "license": "MIT", "dependencies": { "bluebird": "^3.3.4", diff --git a/src/watcher/model-watcher.ts b/src/watcher/model-watcher.ts index 40eb837..60007c9 100644 --- a/src/watcher/model-watcher.ts +++ b/src/watcher/model-watcher.ts @@ -102,21 +102,18 @@ export class ModelWatcher implements IModelWatcher }); hasValue = false; - currentValue = null; - try { currentValue = this.propertyResolver.resolveProperty(this.model, paramRoute); hasValue = true; } - catch (ex) { - currentValue = null; - } + catch (ex) {} if(currentValue == null && (anyRulesAreForEach || anyRulesAreSets)) { if (anyRulesAreForEach) { currentValue = []; } else if (anyRulesAreSets) { currentValue = {}; } + else { currentValue = null; } } parameterRules.forEach((rule) => { @@ -170,31 +167,31 @@ export class ModelWatcher implements IModelWatcher if(this.watchCache.length == 0) { return; } var refreshOnNextCycle = false; - console.log("watcher cache", this.watchCache); this.watchCache.forEach((propertyWatcher: PropertyWatcher) => { var currentValue; + var hasChanged = false; + try - { - currentValue = this.propertyResolver.resolveProperty(this.model, propertyWatcher.propertyPath); - } - catch(ex) - { - currentValue = propertyWatcher.previousValue; - } + { currentValue = this.propertyResolver.resolveProperty(this.model, propertyWatcher.propertyPath); } + catch(ex) { } + + if(typeof(currentValue) == "undefined") + { currentValue = propertyWatcher.previousValue; } if(propertyWatcher.previousValue && propertyWatcher.previousValue.isArray) { var currentLength = currentValue.length || 0; - - console.log("has changed?", currentLength != propertyWatcher.previousValue.length); if(currentLength != propertyWatcher.previousValue.length) - { refreshOnNextCycle = true; } + { hasChanged = true; } } else if (currentValue !== propertyWatcher.previousValue) { var propertyChangedArgs = new PropertyChangedEvent(propertyWatcher.propertyPath, currentValue, propertyWatcher.previousValue); setTimeout(() => { this.onPropertyChanged.publish(propertyChangedArgs); }, 1); propertyWatcher.previousValue = currentValue; } + + if(hasChanged) + { refreshOnNextCycle = true; } }); if(refreshOnNextCycle) diff --git a/tests/specs/model-watcher-tests.js b/tests/specs/model-watcher-tests.js index b664489..ee5bee6 100644 --- a/tests/specs/model-watcher-tests.js +++ b/tests/specs/model-watcher-tests.js @@ -219,15 +219,12 @@ describe('Model Watcher', function () { var spySubscription = chai.spy(function(eventArgs){ console.log("event", eventArgs); }); modelWatcher.onPropertyChanged.subscribe(spySubscription); - dummyModel = { - foo: 11, - bar: [11, 12] - }; + dummyModel.foo = 11; + dummyModel.bar = [11, 12]; setTimeout(function(){ // once for foo, once for bar, once for bar[0] and then bar[1] expect(spySubscription).to.have.been.called.exactly(4); - expect(true).to.equal(false); modelWatcher.stopWatching(); done(); }, 250);