A Pen by francesco agati on CodePen.
Last active
August 29, 2015 14:07
-
-
Save francescoagati/1341829992261994089f to your computer and use it in GitHub Desktop.
A Pen by francesco agati.
This file contains hidden or 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
<div id="counter1"></div> | |
<span id="counter2"></span> | |
<span id="incr">[+]</span> |
This file contains hidden or 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
h = mercury.h | |
diff = (stream) -> | |
stream.patches = mercury.diff stream.old-frame,stream.new-frame | |
stream | |
patch = (streams) -> request-animation-frame -> | |
for stream in streams | |
node = document.get-element-by-id(stream.node-id) | |
if node.children.length is 0 | |
child = mercury.create stream.new-frame | |
node.append-child child | |
else | |
mercury.patch node.children.0, stream.patches | |
acc = (old-frame,new-frame) -> | |
| old-frame is null => new-frame:new-frame,old-frame:new-frame | |
| _ => new-frame:new-frame,old-frame:old-frame | |
pipeline-rendering = new Bacon.Bus! | |
pipeline-rendering.map(diff) | |
.bufferWithTimeOrCount(16, 3) | |
.do-action(patch) | |
.log! | |
render-fn = (counter) -> | |
-> | |
h \div do | |
* h \span "Hello counter " | |
h \span "#{counter++}" | |
render1 = do -> | |
template = render-fn 0 | |
Bacon.from-poll 100, -> new Bacon.Next template! | |
.diff(null,acc) | |
.map -> it.node-id = 'counter1'; it; | |
.log! | |
render2 = do -> | |
template = render-fn 0 | |
stream = $(document.body) | |
.as-event-stream \click,'#incr' | |
.to-property "" | |
.map -> template! | |
.diff(null,acc) | |
.map -> it.node-id = 'counter2'; it; | |
stream | |
pipeline-rendering.plug render1 | |
pipeline-rendering.plug render2 |
This file contains hidden or 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
html, body, #map-canvas { | |
height: 100%; | |
margin: 0px; | |
padding: 0px | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment