-
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.
Adds
Polymer.dom(element).observeChildren(callback)
api
- Loading branch information
Steven Orvell
committed
Aug 4, 2015
1 parent
f34fb45
commit 6499e83
Showing
3 changed files
with
230 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
|
||
<title>observeChildren</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-content'> | ||
<template> | ||
[<content></content>] | ||
</template> | ||
<script> | ||
Polymer({ | ||
is:'test-content', | ||
created: function() { | ||
Polymer.dom(this).observeChildren(function(info) { | ||
console.log('test-content', info); | ||
}); | ||
} | ||
}); | ||
</script> | ||
</dom-module> | ||
|
||
<dom-module id='test-static'> | ||
<template> | ||
My children do not render. | ||
</template> | ||
<script> | ||
Polymer({ | ||
is:'test-static', | ||
created: function() { | ||
Polymer.dom(this).observeChildren(function(info) { | ||
console.log('test-static', info); | ||
}); | ||
} | ||
}); | ||
</script> | ||
</dom-module> | ||
|
||
<test-content id="content"> | ||
<div>content A</div> | ||
<div>content B</div> | ||
</test-content> | ||
|
||
<br><br> | ||
|
||
<test-static id="stat"><div>static A</div><div>static B</div></test-static> | ||
|
||
<script> | ||
Polymer.dom(content).flush(); | ||
Polymer.dom(stat).flush(); | ||
console.group('test dynamic'); | ||
function obs(mxns) { | ||
console.log('custom observer', mxns); | ||
} | ||
var hc = Polymer.dom(content).observeChildren(obs); | ||
var hs = Polymer.dom(stat).observeChildren(obs); | ||
|
||
var d = document.createElement('div'); | ||
d.id = 'foo'; | ||
d.innerHTML = 'Dynamic!'; | ||
Polymer.dom(content).appendChild(d); | ||
Polymer.dom(stat).appendChild(d); | ||
Polymer.dom(content).flush(); | ||
Polymer.dom(stat).flush(); | ||
Polymer.dom(content).unobserveChildren(hc); | ||
Polymer.dom(stat).unobserveChildren(hs); | ||
Polymer.dom(stat).removeChild(d); | ||
Polymer.dom(stat).flush(); | ||
console.groupEnd('test dynamic'); | ||
</script> | ||
|
||
</body> | ||
</html> |