Last active
March 2, 2016 23:07
-
-
Save freeman-lab/02789613f2113c836d01 to your computer and use it in GitHub Desktop.
input handling with virtual or morphing doms
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
| var morphdom = require('morphdom') | |
| var el1 = document.createElement('div') | |
| el1.innerHTML = 'foo' | |
| var el2 = document.createElement('div') | |
| el2.innerHTML = 'bar' | |
| var input1 = document.createElement('input') | |
| var input2 = document.createElement('input') | |
| el1.appendChild(input1) | |
| el2.appendChild(input2) | |
| input1.oninput = function () { | |
| morphdom(el1, el2) | |
| } | |
| document.body.appendChild(el1) |
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
| var vdom = require('virtual-dom') | |
| var hyperx = require('hyperx') | |
| var main = require('main-loop') | |
| var hx = hyperx(vdom.h) | |
| function oninput () { | |
| loop.update({value: 'bar'}) | |
| } | |
| var el = function (state) { | |
| return hx`<div>${state.value}<input oninput=${oninput}></div>` | |
| } | |
| var loop = main({value: 'foo'}, render, vdom) | |
| document.body.appendChild(loop.target) | |
| function render (state) { | |
| return el(state) | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if the following is added to
morphthen the input is preserved after typing