Skip to content

Instantly share code, notes, and snippets.

@tomchentw tomchentw/handleDoOnce.js
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.