Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move notify event target check to _notifyListener. #1323

Merged
merged 2 commits into from
Mar 23, 2015
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
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