Last active
August 29, 2015 14:11
-
-
Save srph/59099c60d58bb553f75a to your computer and use it in GitHub Desktop.
reflux sample (best practices) attempt
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
| // let's say we have this directory | |
| /** | |
| |-- app/ | |
| | |-- Post/ | |
| | | |-- index/ | |
| | | |-- create/ | |
| | | | | |-- PostCreateStore.js | |
| | | | | |-- PostCreate.js | |
| | | |-- edit/ | |
| | | |-- PostActions.js | |
| |-- components/ | |
| | |-- PostCreate/ | |
| | | |-- PostCreateForm.js | |
| | | |-- PostCreateButton.js | |
| | | |-- Whatever.js | |
| | |-- // other components | |
| |-- app.js | |
| */ | |
| // other requires | |
| var PostCreate = require('./app/Post/create/PostCreate'); | |
| // Routes, etc | |
| var routes = ( | |
| <Route path="/posts"> | |
| // Other routes | |
| // index, edit.. etc | |
| <Route path="/create" handler={PostCreate}"> | |
| </Route> | |
| ) | |
| // Run react-router. |
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 Reflux = require('reflux'); | |
| module.exports = Reflux.createAction([ | |
| // other things | |
| onCreateSuccess, | |
| onCreateError | |
| ]); |
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
| /** @jsx React.DOM */ | |
| var React = require('react'); | |
| var Reflux = require('reflux'); | |
| var PostCreateStore = require('./PostCreateStore'); | |
| var PostCreateForm = require('../../components/PostCreate/PostCreateForm'); | |
| // The main template or component for the PostCreate module itself | |
| var PostCreate = React.createClass({ | |
| mixins: [Reflux.connect(todoListStore,"list")] | |
| }); |
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
| /** @jsx React.DOM */ | |
| var React = require('react'); | |
| var Reflux = require('reflux'); | |
| var PostCreateButton = require('./PostCreateButton'); | |
| // A component used to handle the form (uses PostCreateButton) | |
| // receives prop | |
| // handleCreateSuccess | |
| // handleCreateError | |
| var PostCreateForm = React.createClass({ | |
| getInitialState: function() { return { loading: false }; }, | |
| render: function() { | |
| return ( | |
| // Input whatever | |
| // Label whatever | |
| <PostCreateButton data={this.state.data} | |
| handleCreateSuccess={this.props.handleCreateSuccess} | |
| handleCreateError={this.props.handleCreateError} /> | |
| ); | |
| } | |
| }); | |
| module.exports = PostCreateForm; |
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 Reflux = require('reflux'); | |
| var PostActions = require('../PostActions'); | |
| var _data = {}; | |
| module.exports = { | |
| listenables: [PostActions], | |
| onCreateSuccess: function(data) { /** do */ }, | |
| onCreateError: function(data) { /** do */ }, | |
| // updates data, trigger | |
| _update: function(data) { } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment