From f550e2538a20412bb15a64a4830c8786aa36c4a0 Mon Sep 17 00:00:00 2001 From: Josh Perez Date: Fri, 8 May 2015 19:46:32 -0700 Subject: [PATCH] stop loading for errors as well --- src/alt/store/StoreMixin.js | 16 +++++++++------- stargazer.js | 4 ++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/alt/store/StoreMixin.js b/src/alt/store/StoreMixin.js index cdcdf306..db1f3143 100644 --- a/src/alt/store/StoreMixin.js +++ b/src/alt/store/StoreMixin.js @@ -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() @@ -59,7 +61,7 @@ const StoreMixin = { }, {}) this.exportPublicMethods(toExport) - this.exportPublicMethods({ isLoading: _ => isLoading }) + this.exportPublicMethods({ isLoading: () => isLoading }) }, exportPublicMethods(methods) { diff --git a/stargazer.js b/stargazer.js index aa6d47cc..75ffaef6 100644 --- a/stargazer.js +++ b/stargazer.js @@ -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 },