-
-
Save subtleGradient/5686817 to your computer and use it in GitHub Desktop.
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
<element name="comment-form" constructor="CommentForm"> | |
<template> | |
<form class="commentForm" onSubmit={this.handleSubmit}> | |
<input type="text" placeholder="Your name" ref="author" /> | |
<input | |
type="text" | |
placeholder="Say something..." | |
ref="text" | |
/> | |
</form> | |
</template> | |
<script> | |
CommentForm.prototype.handleSubmit = function(){ | |
var author = this.refs.author.getDOMNode().value.trim(); | |
var text = this.refs.text.getDOMNode().value.trim(); | |
if (!text || !author) { | |
return; | |
} | |
// TODO: send request to the server | |
this.refs.author.getDOMNode().value = ''; | |
this.refs.text.getDOMNode().value = ''; | |
} | |
</script> | |
</element> |
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
<element name="timer" constructor="Timer"> | |
<template> | |
<div>Seconds Elapsed: {{this.state.secondsElapsed}}</div> | |
</template> | |
<script> | |
Timer = React.createClass({ | |
getInitialState: function() { | |
return {secondsElapsed: 0}; | |
}, | |
tick: function() { | |
this.setState({secondsElapsed: this.state.secondsElapsed + 1}); | |
}, | |
componentDidMount: function() { | |
setInterval(this.tick.bind(this), 1000); | |
} | |
}); | |
</script> | |
</element> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cf. http://html5-demos.appspot.com/static/webcomponents/index.html#62