Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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))
}
exports.Referred = {
QUERY: 'QUERY',
QUERY_COMPLETED: 'QUERY_COMPLETED',
QUERY_FAILED: 'QUERY_FAILED'
}
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
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
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
You can’t perform that action at this time.