Created
September 23, 2015 22:07
Revisions
-
dinks created this gist
Sep 23, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ var BudgetApp = React.createClass({ mixins: [Reflux.connect(EntryStore, 'entries')], render: function() { return ( ); } }); 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ var EntryActions = Reflux.createActions([ "entryCreate", "entryUpdate", "entryDestroy" ]); 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ var EntryRow = React.createClass({ _onRemoveClick: function() { EntryActions.entryDestroy(this.props.entry.id); }, render: function () { var entry = this.props.entry; return ( <tr> <td>{entry.title}</td> <td className={entry.amount > 0 ? 'success' : 'danger'}>{entry.amount.toFixed(2)}</td> <td>{entry.category}</td> <td>{entry.timestamp.toLocaleFormat()}</td> <td><a href="#" onClick={this._onRemoveClick}>REMOVE</a></td> </tr> ); } }); 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ var Reflux = require('reflux'); var EntryActions = require('../actions/entry_actions'); var assign = require('object-assign'); var _entries = {}; var EntryStore = Reflux.createStore({ listenables: [EntryActions], getInitialState: function() { return _entries; }, entryCreate: function(title, amount, category) { var id = (+new Date() + Math.floor(Math.random() * 999999)).toString(36); _entries[id] = { id: id, title: title, amount: amount, category: category, timestamp: (new Date()) }; this.trigger(_entries); }, entryUpdate: function(id, updates) { _entries[id] = assign({}, _entries[id], updates); this.trigger(_entries); }, entryDestroy: function(id) { delete _entries[id]; this.trigger(_entries); } });