Last active
September 28, 2016 17:58
-
-
Save mlrawlings/097482dd21ef94cbed25bba15198975f to your computer and use it in GitHub Desktop.
Some thoughts on an approach to stateful rerendering
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
/* | |
Some thoughts on an approach to stateful rerendering. | |
This definitely has some problems with more complex components | |
that would need solving. | |
*/ | |
// input | |
class Foo { | |
render() { | |
return <div>Hello {this.state.name}</div>; | |
} | |
} | |
// generated output for server | |
class Foo { | |
render() { | |
return '<div>Hello '+this.state.name+'</div>'; | |
} | |
} | |
// generated output for browser | |
class Foo { | |
render(data) { | |
return { | |
render:render_Foo, | |
update:update_Foo, | |
v0:this.state.name | |
}; | |
} | |
} | |
function render_Foo(vars) { | |
var n0 = document.createElement('div'); | |
var n1 = document.createTextNode('Hello '+vars.v0); | |
n0.appendChild(n1); | |
return { | |
n0, | |
n1 | |
}; | |
} | |
function update_Foo(domNodes, oldVars, newVars) { | |
if(newVars.v0 !== oldVars.v0) { | |
domNodes.n1.nodeValue = 'Hello '+newVars.v0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment