Last active
August 29, 2015 14:23
-
-
Save tomchentw/b462f574164ac117a276 to your computer and use it in GitHub Desktop.
handleDoOnce.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 可能可以改寫成這樣: | |
LocationsFetcher.fetchLastResult = null; | |
LocationsFetcher.fetch = () => | |
if (LocationsFetcher.fetchLastResult) { | |
return Promise.reject(new AlreadyCalledError()); | |
} else { | |
return LocationsFetcher.fetchLastResult = doFetchInternal(); | |
} | |
}; | |
// Then in your store | |
handleLocationsFailed(error) { | |
if (error instanceof AlreadyCalledError) { | |
return; // Do nothing, or ...? | |
} | |
this.fetchError = error.message; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment