From b221dbe63df6fec71707515e1db1abacea757a82 Mon Sep 17 00:00:00 2001 From: Kevin Schaaf Date: Thu, 3 Sep 2015 20:18:54 -0700 Subject: [PATCH 1/3] Allow multiple paths to be linked using linkPath. Fixes #2048 --- src/standard/notify-path.html | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/standard/notify-path.html b/src/standard/notify-path.html index 5556c35017..9fd0d3c20e 100644 --- a/src/standard/notify-path.html +++ b/src/standard/notify-path.html @@ -278,7 +278,7 @@ this._boundPaths[to] = from; // this.set(to, this.get(from)); } else { - this.unbindPath(to); + this.unlinkPaths(to); // this.set(to, from); } }, @@ -303,19 +303,10 @@ for (var a in this._boundPaths) { var b = this._boundPaths[a]; if (path.indexOf(a + '.') == 0) { - from = a; - to = b; - break; + this.notifyPath(this._fixPath(b, a, path), value); + } else if (path.indexOf(b + '.') == 0) { + this.notifyPath(this._fixPath(a, b, path), value); } - if (path.indexOf(b + '.') == 0) { - from = b; - to = a; - break; - } - } - if (from && to) { - var p = this._fixPath(to, from, path); - this.notifyPath(p, value); } }, From ab858844115f8246aa43930e4e2ffb1ca3c9e1e9 Mon Sep 17 00:00:00 2001 From: Kevin Schaaf Date: Thu, 3 Sep 2015 21:36:44 -0700 Subject: [PATCH 2/3] Remove dead code; add tests. --- src/standard/notify-path.html | 1 - test/unit/notify-path-elements.html | 10 ++++- test/unit/notify-path.html | 57 +++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 3 deletions(-) diff --git a/src/standard/notify-path.html b/src/standard/notify-path.html index 9fd0d3c20e..8875cf5df5 100644 --- a/src/standard/notify-path.html +++ b/src/standard/notify-path.html @@ -299,7 +299,6 @@ }, _notifyBoundPaths: function(path, value) { - var from, to; for (var a in this._boundPaths) { var b = this._boundPaths[a]; if (path.indexOf(a + '.') == 0) { diff --git a/test/unit/notify-path-elements.html b/test/unit/notify-path-elements.html index 2d386d01d5..4afbae4a85 100644 --- a/test/unit/notify-path-elements.html +++ b/test/unit/notify-path-elements.html @@ -125,7 +125,10 @@ 'multiplePathsChanged(a, nested.b, nested.obj.c)', 'arrayChanged(array.splices)', 'arrayNoCollChanged(arrayNoColl.splices)', - 'arrayOrPropChanged(prop, array.splices)' + 'arrayOrPropChanged(prop, array.splices)', + 'aChanged(a.*)', + 'bChanged(b.*)', + 'cChanged(c.*)' ], created: function() { this.observerCounts = { @@ -219,7 +222,10 @@ arrayOrPropChanged: function(prop, splices) { this.observerCounts.arrayOrPropChanged++; assert.equal(prop, this.prop); - } + }, + aChanged: function() {}, + bChanged: function() {}, + cChanged: function() {} }); \ No newline at end of file diff --git a/test/unit/notify-path.html b/test/unit/notify-path.html index e4d266bb1e..e84cb1124e 100644 --- a/test/unit/notify-path.html +++ b/test/unit/notify-path.html @@ -1153,6 +1153,63 @@ assert.strictEqual(el.array[3], 'orig3'); }); + test('link two objects', function() { + var aChanged = 0; + var bChanged = 0; + el.a = el.b = {}; + el.linkPaths('b', 'a'); + el.aChanged = function() { aChanged++; }; + el.bChanged = function() { bChanged++; }; + el.set('a.foo', 1); + assert.equal(aChanged, 1); + assert.equal(bChanged, 1); + }); + + test('link three objects', function() { + var aChanged = 0; + var bChanged = 0; + var cChanged = 0; + el.a = el.b = el.c = {}; + el.linkPaths('b', 'a'); + el.linkPaths('c', 'a'); + el.aChanged = function() { aChanged++; }; + el.bChanged = function() { bChanged++; }; + el.cChanged = function() { cChanged++; }; + el.set('a.foo', 1); + assert.equal(aChanged, 1); + assert.equal(bChanged, 1); + assert.equal(cChanged, 1); + }); + + test('link two arrays', function() { + var aChanged = 0; + var bChanged = 0; + el.a = el.b = []; + el.linkPaths('b', 'a'); + el.aChanged = function() { aChanged++; }; + el.bChanged = function() { bChanged++; }; + el.set('a.foo', 1); + assert.equal(aChanged, 1); + assert.equal(bChanged, 1); + }); + + test('link three arrays', function() { + var aChanged = 0; + var bChanged = 0; + var cChanged = 0; + el.a = el.b = el.c = []; + el.linkPaths('b', 'a'); + el.linkPaths('c', 'a'); + el.aChanged = function() { aChanged++; }; + el.bChanged = function() { bChanged++; }; + el.cChanged = function() { cChanged++; }; + el.push('a', {}); + // 2 changes for arrays (splices & length) + assert.equal(aChanged, 2); + assert.equal(bChanged, 2); + assert.equal(cChanged, 2); + }); + }); From bee110b52d7565d750ecc8f4120894b8e57143f7 Mon Sep 17 00:00:00 2001 From: Kevin Schaaf Date: Fri, 4 Sep 2015 19:13:58 -0700 Subject: [PATCH 3/3] Add unlinkPath tests. --- test/unit/notify-path.html | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/test/unit/notify-path.html b/test/unit/notify-path.html index e84cb1124e..0408a543e7 100644 --- a/test/unit/notify-path.html +++ b/test/unit/notify-path.html @@ -1163,6 +1163,10 @@ el.set('a.foo', 1); assert.equal(aChanged, 1); assert.equal(bChanged, 1); + el.unlinkPaths('b'); + el.set('a.foo', 2); + assert.equal(aChanged, 2); + assert.equal(bChanged, 1); }); test('link three objects', function() { @@ -1179,6 +1183,11 @@ assert.equal(aChanged, 1); assert.equal(bChanged, 1); assert.equal(cChanged, 1); + el.unlinkPaths('b'); + el.set('a.foo', 2); + assert.equal(aChanged, 2); + assert.equal(bChanged, 1); + assert.equal(cChanged, 2); }); test('link two arrays', function() { @@ -1188,9 +1197,14 @@ el.linkPaths('b', 'a'); el.aChanged = function() { aChanged++; }; el.bChanged = function() { bChanged++; }; - el.set('a.foo', 1); - assert.equal(aChanged, 1); - assert.equal(bChanged, 1); + el.push('a', {}); + // 2 changes for arrays (splices & length) + assert.equal(aChanged, 2); + assert.equal(bChanged, 2); + el.unlinkPaths('b'); + el.push('a', {}); + assert.equal(aChanged, 4); + assert.equal(bChanged, 2); }); test('link three arrays', function() { @@ -1208,6 +1222,11 @@ assert.equal(aChanged, 2); assert.equal(bChanged, 2); assert.equal(cChanged, 2); + el.unlinkPaths('b'); + el.push('a', {}); + assert.equal(aChanged, 4); + assert.equal(bChanged, 2); + assert.equal(cChanged, 4); }); });