Created
October 29, 2014 21:08
-
-
Save jergason/1b13929d32cff4f0e501 to your computer and use it in GitHub Desktop.
cursors woooo
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 React = require('react'); | |
var History = require('immutable-history'); | |
// call `render` whenever the cursor changes | |
var state = new History({posts: [], username: 'Jamitron The Terrible'}, render); | |
var App = React.createClass({ | |
render: function() { | |
var postsCursor = this.props.data.cursor(['posts']); | |
return <div> | |
<Posts posts={postsCursor} /> | |
</div> | |
} | |
}); | |
var Posts = React.createClass({ | |
render: function() { | |
var posts = this.props.posts.map(function(p) { | |
return <li>Sup</li>; | |
}); | |
return <ul> | |
{posts} | |
</ul> | |
} | |
}); | |
function render(cursor) { | |
React.renderComponent(<App data={cursor} />, document.body); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment