Skip to content

Commit

Permalink
stop loading for errors as well
Browse files Browse the repository at this point in the history
  • Loading branch information
goatslacker committed May 9, 2015
1 parent 41601ae commit f550e25
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
16 changes: 9 additions & 7 deletions src/alt/store/StoreMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,21 @@ const StoreMixin = {

publicMethods[methodName] = (...args) => {
const state = this.getInstance().getState()
const value = asyncSpec.cache && asyncSpec.cache(state, ...args)
const value = asyncSpec.local && asyncSpec.local(state, ...args)

// if we don't have it in cache then fetch it
if (!value) {
isLoading = true
if (asyncSpec.loading) asyncSpec.loading()
asyncSpec.fetch(state, ...args)
.then(v => {
asyncSpec.remote(state, ...args)
.then((v) => {
isLoading = false
return v
return asyncSpec.success(v)
})
.catch((v) => {
isLoading = false
return asyncSpec.error(v)
})
.then(asyncSpec.success)
.catch(asyncSpec.error)
} else {
// otherwise emit the change now
this.emitChange()
Expand All @@ -59,7 +61,7 @@ const StoreMixin = {
}, {})

this.exportPublicMethods(toExport)
this.exportPublicMethods({ isLoading: _ => isLoading })
this.exportPublicMethods({ isLoading: () => isLoading })
},

exportPublicMethods(methods) {
Expand Down
4 changes: 2 additions & 2 deletions stargazer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ const StargazerActions = alt.generateActions(

const StargazerSource = {
fetchUsers: {
fetch(state) {
remote(state) {
const url = `https://api.github.com/repos/${state.user}/${state.repo}/stargazers`
return axios({ url }).then(response => response.data)
},

cache(state) {
local(state) {
return state.users.length ? state.users : null
},

Expand Down

0 comments on commit f550e25

Please sign in to comment.