Created
September 23, 2015 22:07
-
-
Save dinks/4fe731e88a32ce729779 to your computer and use it in GitHub Desktop.
reflux Stuff
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 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 characters
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 characters
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 characters
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); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment