-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
Polymer.dom().notifyObservers
method to 'kick' observers, for e…
…xample, when attributes change under Shadow DOM.
- Loading branch information
Steven Orvell
committed
Aug 13, 2015
1 parent
b11f86b
commit 07261e4
Showing
6 changed files
with
203 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
|
||
<title>observeReNodes</title> | ||
|
||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
|
||
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script> | ||
<link rel="import" href="../../polymer.html"> | ||
|
||
</head> | ||
<body> | ||
|
||
<dom-module id='test-inner'> | ||
<template> | ||
~<content id="c" select=".a"></content>~ | ||
</template> | ||
<script> | ||
Polymer({ | ||
is:'test-inner', | ||
ready: function() { | ||
this.observe(); | ||
}, | ||
|
||
observe: function() { | ||
this._childObserver = Polymer.dom(this).observeNodes(function(info) { | ||
info.addedNodes.forEach(function(n) { | ||
if (n.nodeType === Node.ELEMENT_NODE) { | ||
console.log('added:', n.localName, n.textContent); | ||
} | ||
}); | ||
info.removedNodes.forEach(function(n) { | ||
if (n.nodeType === Node.ELEMENT_NODE) { | ||
console.log('removed:', n.localName, n.textContent); | ||
} | ||
}); | ||
}); | ||
this._contentObserver = Polymer.dom(this.$.c).observeNodes(function(info) { | ||
info.addedNodes.forEach(function(n) { | ||
if (n.nodeType === Node.ELEMENT_NODE) { | ||
console.log('%c content added:', 'color: blue;', n.localName, n.textContent); | ||
} | ||
}); | ||
info.removedNodes.forEach(function(n) { | ||
if (n.nodeType === Node.ELEMENT_NODE) { | ||
console.log('%c content removed:', 'color: blue;', n.localName, n.textContent); | ||
} | ||
}); | ||
}, true); | ||
}, | ||
|
||
unobserve: function() { | ||
Polymer.dom(this).unobserveNodes(this._childObserver); | ||
Polymer.dom(this).unobserveNodes(this._contentObserver); | ||
} | ||
}); | ||
</script> | ||
</dom-module> | ||
|
||
<dom-module id='test-content'> | ||
<template> | ||
<test-inner id="inner">[<content id="ip" select=".b"></content>]</test-inner> | ||
</template> | ||
<script> | ||
(function() { | ||
Polymer({ | ||
is:'test-content' | ||
}); | ||
})(); | ||
</script> | ||
</dom-module> | ||
|
||
<test-content id="content"> | ||
<div class="a b">content A</div> | ||
<div class="a b">content B</div> | ||
</test-content> | ||
|
||
<br><br> | ||
|
||
<script> | ||
|
||
function makeNode(text) { | ||
var d = document.createElement('div'); | ||
d.textContent = text;; | ||
return d; | ||
} | ||
|
||
|
||
Polymer.dom.flush(); | ||
|
||
// setTimeout(function() { | ||
console.group('test dynamic'); | ||
var d = makeNode('dynamic!'); | ||
Polymer.dom.flush(); | ||
Polymer.dom(content).appendChild(d); | ||
Polymer.dom.flush(); | ||
Polymer.dom(content).removeChild(d); | ||
Polymer.dom.flush(); | ||
d = makeNode('1'); | ||
Polymer.dom(d).classList.add('b'); | ||
Polymer.dom(content).appendChild(d); | ||
Polymer.dom.flush(); | ||
Polymer.dom(d).classList.add('a'); | ||
Polymer.dom(Polymer.dom(d).parentNode).notifyObservers(); | ||
Polymer.dom(content.$.inner).appendChild(makeNode('2')); | ||
Polymer.dom.flush(); | ||
d = makeNode('-1'); | ||
Polymer.dom(d).classList.add('b'); | ||
Polymer.dom(d).classList.add('a'); | ||
Polymer.dom(content).insertBefore(d, Polymer.dom(content).firstChild); | ||
Polymer.dom.flush(); | ||
Polymer.dom(content.$.inner).insertBefore(makeNode('-2'), Polymer.dom(content.$.inner).firstChild); | ||
Polymer.dom.flush(); | ||
Polymer.dom(content.$.inner).removeChild(Polymer.dom(content.$.inner).firstChild); | ||
Polymer.dom(content.$.inner).removeChild(Polymer.dom(content.$.inner).lastChild); | ||
Polymer.dom(content).removeChild(Polymer.dom(content).firstChild); | ||
Polymer.dom(content).removeChild(Polymer.dom(content).lastChild); | ||
Polymer.dom.flush(); | ||
console.groupEnd('test dynamic'); | ||
// }, 1000); | ||
</script> | ||
|
||
</body> | ||
</html> |