Skip to content

Commit

Permalink
Merge pull request #1323 from Polymer/0.8-notify-fix
Browse files Browse the repository at this point in the history
Move notify event target check to _notifyListener.
  • Loading branch information
Steve Orvell committed Mar 23, 2015
2 parents adc4e2f + 0c3ac51 commit e63011f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 30 deletions.
12 changes: 8 additions & 4 deletions src/features/standard/configure.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,14 @@
// effects and side effects must not be processed before ready time,
// handling is queue/defered until then.
_notifyListener: function(fn, e) {
if (!this._readied) {
this._queueHandler(arguments);
} else {
return fn.call(this, e);
// TODO(kschaaf): This target check really belongs in the generated
// handler, but e.target is no longer valid after queueing
if (!e.path || e.path[0] == e.target) {
if (!this._readied) {
this._queueHandler(arguments);
} else {
return fn.call(this, e);
}
}
},

Expand Down
10 changes: 4 additions & 6 deletions src/lib/bind/bind.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@
'\t}';
}
changedFn =
'if (!e.path || e.path[0] == e.target) {\n' +
'\tif (e.detail.path) {\n' +
'\t\tvar path = this._fixPath(\'' + path + '\', \'' +
'if (e.detail.path) {\n' +
'\tvar path = this._fixPath(\'' + path + '\', \'' +
property + '\', e.detail.path);\n' +
'\t\tthis.notifyPath(path, e.detail.value);\n' +
'\t} else {\n' +
'\tthis.notifyPath(path, e.detail.value);\n' +
'} else {\n' +
changedFn + '\n' +
'\t}\n' +
'}';
//
model._bindListeners.push({
Expand Down
5 changes: 4 additions & 1 deletion test/unit/bind-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,16 @@
notifies: {
notify: true
}
},
ready: function() {
this.notifies = 'readyValue';
}
});
</script>

<dom-module id="x-notifies2">
<template>
<x-notifies1 id="notifies1"></x-notifies1>
<x-notifies1 id="notifies1" notifies="{{shouldChange}}"></x-notifies1>
</template>
</dom-module>
<script>
Expand Down
50 changes: 31 additions & 19 deletions test/unit/bind.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@

var el;

beforeEach(function() {
setup(function() {
el = document.createElement('x-basic');
document.body.appendChild(el);
});

afterEach(function() {
teardown(function() {
document.body.removeChild(el);
});

Expand Down Expand Up @@ -230,12 +230,12 @@

var el;

beforeEach(function() {
setup(function() {
el = document.createElement('x-compose');
document.body.appendChild(el);
});

afterEach(function() {
teardown(function() {
document.body.removeChild(el);
});

Expand Down Expand Up @@ -344,12 +344,12 @@

var el;

beforeEach(function() {
setup(function() {
el = document.createElement('x-compose');
document.body.appendChild(el);
});

afterEach(function() {
teardown(function() {
document.body.removeChild(el);
});

Expand Down Expand Up @@ -433,12 +433,12 @@

var el;

beforeEach(function() {
setup(function() {
el = document.createElement('x-reflect');
document.body.appendChild(el);
});

afterEach(function() {
teardown(function() {
document.body.removeChild(el);
});

Expand Down Expand Up @@ -527,12 +527,12 @@

var el;

beforeEach(function() {
setup(function() {
el = document.createElement('x-basic');
document.body.appendChild(el);
});

afterEach(function() {
teardown(function() {
document.body.removeChild(el);
});

Expand Down Expand Up @@ -596,21 +596,33 @@
suite('avoid non-bubbling event gotchas', function() {

var el;
var container;

beforeEach(function() {
el = document.createElement('x-notifies3');
document.body.appendChild(el);
setup(function() {
container = document.createElement('div');
document.body.appendChild(container);
container.innerHTML = '<x-notifies3></x-notifies3>';
if (window.CustomElements) {
CustomElements.takeRecords();
}
el = container.firstChild;
});

afterEach(function() {
document.body.removeChild(el);
teardown(function() {
document.body.removeChild(container);
});

test('avoid non-bubbling event gotchas', function() {
el.shouldNotChangeChanged = function(e) {
assert(false, 'parent notifies should not have changed');
};
el.$.notifies2.$.notifies1.notifies = 42;
el.$.notifies2.$.notifies1.notifies = 'runtimeValue';
assert.equal(el.$.notifies2.$.notifies1.notifies, 'runtimeValue');
assert.equal(el.$.notifies2.shouldChange, 'runtimeValue');
assert.notEqual(el.shouldNotChange, 'runtimeValue');
});

test('avoid non-bubbling event gotchas at ready time', function() {
assert.equal(el.$.notifies2.$.notifies1.notifies, 'readyValue');
assert.equal(el.$.notifies2.shouldChange, 'readyValue');
assert.notEqual(el.shouldNotChange, 'readyValue');
});

});
Expand Down

0 comments on commit e63011f

Please sign in to comment.