Skip to content

Instantly share code, notes, and snippets.

@tomchentw
Last active August 29, 2015 14:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomchentw/b462f574164ac117a276 to your computer and use it in GitHub Desktop.
Save tomchentw/b462f574164ac117a276 to your computer and use it in GitHub Desktop.
handleDoOnce.js
// 可能可以改寫成這樣:
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