Skip to content

Instantly share code, notes, and snippets.

@lsanwick
Last active January 16, 2016 00:28
Show Gist options
  • Save lsanwick/577a047bd1f44a2e5919 to your computer and use it in GitHub Desktop.
Save lsanwick/577a047bd1f44a2e5919 to your computer and use it in GitHub Desktop.
Alt JS Loading Bug
OrderSource = {
fetchOrders: {
remote: -> axios.get('/orders.json'),
loading: OrderActions.loadingOrders,
success: OrderActions.fetchOrdersCompleted,
error: OrderActions.fetchOrdersFailed,
}
}
module.exports = OrderSource
class OrdersPage extends React.Component
@getStores: (props) ->
[OrderStore]
@getPropsFromStores: (props) ->
OrderStore.getState()
componentDidMount: ->
OrderStore.fetchOrders()
loadingIndicator: ->
return unless @props.loading
<FontAwesome className="loading-indicator" name="refresh" size="2x" spin />
render: ->
<div>
{@loadingIndicator()}
</div>
module.exports = connectToStores(OrdersPage)
class OrderStore
constructor: ->
@orders = []
@error = null
@loading = false
@bindActions(OrderActions)
@registerAsync(OrderSource)
onLoadingOrders: ->
@error = null
@loading = true
@orders = []
onFetchOrdersCompleted: (response) ->
@error = null
@loading = false
@orders = response.data if response.status == 200
module.exports = alt.createStore(OrderStore, 'OrderStore')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment