Skip to content

Commit

Permalink
Add notifyDomBind to dom-bind.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed Jan 21, 2017
1 parent 4b286f1 commit ad7f91d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 17 deletions.
15 changes: 14 additions & 1 deletion src/lib/template/dom-bind.html
Expand Up @@ -61,6 +61,19 @@

is: 'dom-bind',

properties: {

/**
* When the global `Polymer.Settings.suppressDomChange` setting is used,
* setting `notifyDomChange: true` will enable firing `dom-change` events
* on this element.
*/
notifyDomChange: {
type: Boolean
}

},

extends: 'template',
_template: null,

Expand Down Expand Up @@ -168,7 +181,7 @@
this._children = Polymer.TreeApi.arrayCopyChildNodes(this.root);
}
this._insertChildren();
if (!Polymer.Settings.suppressTemplateNotifications) {
if (!Polymer.Settings.suppressTemplateNotifications || this.notifyDomChange) {
this.fire('dom-change');
}
}
Expand Down
29 changes: 29 additions & 0 deletions test/unit/dom-bind.html
Expand Up @@ -223,6 +223,35 @@

});

suite('dom-change', function() {

test('dom-change when stamped', function(done) {
var bind = document.createElement('template', 'dom-bind');
var changed = sinon.spy();
bind.addEventListener('dom-change', changed);
document.body.appendChild(bind);
setTimeout(function() {
assert.equal(changed.callCount,
Polymer.Settings.suppressTemplateNotifications ? 0 : 1);
done();
});
});

test('re-enable dom-change', function(done) {
if (Polymer.Settings.suppressTemplateNotifications) {
var bind = document.createElement('template', 'dom-bind');
bind.notifyDomChange = true;
var changed = sinon.spy();
bind.addEventListener('dom-change', changed);
document.body.appendChild(bind);
setTimeout(function() {
assert.equal(changed.callCount, 1);
done();
});
}
});

});

</script>

Expand Down
14 changes: 6 additions & 8 deletions test/unit/dom-if.html
Expand Up @@ -699,14 +699,12 @@

test('re-enable dom-change', function() {
if (Polymer.Settings.suppressTemplateNotifications) {
test('enable dom-change on instance', function() {
unconfigured1.$['if-1'].setAttribute('notify-dom-change', '');
unconfigured1.domUpdateHandlerCount = 0;
unconfigured1.shouldStamp = false;
setTimeout(function() {
assert.equal(unconfigured1.domUpdateHandlerCount, 1);
});
});
unconfigured1.$['if-1'].setAttribute('notify-dom-change', '');
unconfigured1.domUpdateHandlerCount = 0;
unconfigured1.shouldStamp = false;
setTimeout(function() {
assert.equal(unconfigured1.domUpdateHandlerCount, 1);
});
}
});

Expand Down
14 changes: 6 additions & 8 deletions test/unit/dom-repeat.html
Expand Up @@ -3874,14 +3874,12 @@ <h4>x-repeat-chunked</h4>

test('re-enable dom-change', function() {
if (Polymer.Settings.suppressTemplateNotifications) {
test('enable dom-change on instance', function() {
unconfigured1.$.repeater.setAttribute('notify-dom-change', '');
unconfigured1.domUpdateHandlerCount = 0;
unconfigured.items = unconfigured.items.slice();
setTimeout(function() {
assert.equal(unconfigured1.domUpdateHandlerCount, 1);
});
});
unconfigured1.$.repeater.setAttribute('notify-dom-change', '');
unconfigured1.domUpdateHandlerCount = 0;
unconfigured.items = unconfigured.items.slice();
setTimeout(function() {
assert.equal(unconfigured1.domUpdateHandlerCount, 1);
});
}
});

Expand Down

0 comments on commit ad7f91d

Please sign in to comment.