Skip to content

Instantly share code, notes, and snippets.

@Sawtaytoes
Last active April 25, 2019 04:49
Show Gist options
  • Save Sawtaytoes/1a83421856e479741db363be3815d6ed to your computer and use it in GitHub Desktop.
Save Sawtaytoes/1a83421856e479741db363be3815d6ed to your computer and use it in GitHub Desktop.
var loadingMiddleware = function(action) {
if (action.type === 'GET_IDS') {
dispatch({
type: 'LOADING',
})
}
if (action.type === 'UPDATE_IDS') {
dispatch({
type: 'LOADED',
})
}
}
var idsMiddleware = function(action) {
if (action.type !== 'GET_IDS') {
return
}
idsService
.get()
.then(function(ids) {
return (
dispatch({
ids: ids,
type: 'UPDATE_IDS',
})
)
})
}
subscribe(loadingMiddleware)
subscribe(idsMiddleware)
vm.onClick = function() {
dispatch({
type: 'GET_IDS',
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment