Created
July 2, 2014 13:25
-
-
Save abrkn/685169acd78aac38b9a0 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
var Constants = require('../constants') | |
exports.query = function() { | |
this.dispatch(Constants.Referred.QUERY) | |
api.call('v1/referred') | |
.then(function(data) { | |
this.dispatch(Constants.Referred.QUERY_COMPLETED, data) | |
}.bind(this), function(err) { | |
this.dispatch(Constants.Referred.QUERY_FAILED, { | |
error: err | |
}) | |
}.bind(this)) | |
} |
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
exports.Referred = { | |
QUERY: 'QUERY', | |
QUERY_COMPLETED: 'QUERY_COMPLETED', | |
QUERY_FAILED: 'QUERY_FAILED' | |
} |
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 Fluxxor = require('fluxxor') | |
var Stores = require('./stores') | |
var stores = { | |
Referred: new Stores.Referred() | |
} | |
var actions = require('./actions') | |
var flux = new Fluxxor.Flux(stores, actions) | |
module.exports = flux |
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 Fluxxor = require('fluxxor') | |
var Constants = require('../constants') | |
var ReferredStore = Fluxxor.createStore({ | |
initialize: function() { | |
this.bindActions( | |
Constants.Referred.QUERY_COMPLETED, this.handleQueryCompleted | |
) | |
}, | |
handleQueryCompleted: function(res) { | |
this.current = res | |
this.emit('change') | |
} | |
}) | |
module.exports = ReferredStore |
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/addons') | |
var Fluxxor = require('fluxxor') | |
var FluxMixin = Fluxxor.FluxMixin(React) | |
var StoreWatchMixin = Fluxxor.StoreWatchMixin | |
var Nav = require('../nav') | |
var format = require('util').format | |
var Referred = React.createClass({ | |
mixins: [FluxMixin, StoreWatchMixin('Referred')], | |
getInitialState: function() { | |
return {} | |
}, | |
componentWillMount: function() { | |
this.getFlux().actions.Referred.query() | |
}, | |
getStateFromFlux: function() { | |
var store = this.getFlux().store('Referred') | |
return { | |
stats: store.current | |
} | |
}, | |
render: function() { | |
if (!this.state.stats) { | |
return <span>Loading...</span> | |
} | |
return <table className="table"> | |
<tr> | |
<th>Total</th> | |
<td>{this.state.stats.referred}</td> | |
</tr> | |
<tr> | |
<th>Paid</th> | |
<td>{this.state.stats.paid}</td> | |
</tr> | |
</table> | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment