We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Guide on managing callback complexity
Could you please send me some code example for structuring a chain of callbacks?
For example using includes to join data or ParseRelation to load associations.
Also, move the callbacks into an object with each request in a method and then use an interface to send out the requests (pseudo-code):
class ObjectFetcher { public interface FetcherCallbacks { void onFirstDataLoaded(Model impartialData); void onAllDataLoaded(Model data); } FetcherCallbacks callback; int requestsLoadedFlag = 0; public ObjectFetcher(FetcherCallbacks callback) { this.callback = callback; } public void loadAll() { sendFirstRequest(); sendSecondRequest(); sendThirdRequest(); } private void sendFirstRequest() { object.findAllInBackground(new Parse { void onDone(Error error) { requestsLoadedFlag +=1; // STORE DATA IN MEMBER VARIABLE HERE callback.onFirstDataLoaded(data); sendFinalDataWhenReady(); } }); } private void sendSecondRequest() { object.findAllInBackground(new Parse { void onDone(Error error) { requestsLoadedFlag +=1; // STORE DATA IN MEMBER VARIABLE HERE sendFinalDataWhenReady(); } }); } private void sendThirdRequest { object.findAllInBackground(new Parse { void onDone(Error error) { requestsLoadedFlag +=1; // STORE DATA IN MEMBER VARIABLE HERE sendFinalDataWhenReady(); } } } private void sendFinalDataWhenReady() { if (requestsLoadedFlag == 3) { callback.onAllDataLoaded(data1, data2, data3); } } }
and then use with something like:
ObjectFetcher fetcher = new ObjectFetcher(new FetcherCallbacks() { void onFirstDataLoaded { // … callback fired here } void onAllDataLoaded { // … callback fired here } })
Note that this is psuedocode but hope it gives you an idea of how to manage things using objects and interface callbacks.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Guide on managing callback complexity
For example using includes to join data or ParseRelation to load associations.
Also, move the callbacks into an object with each request in a method and then use an interface to send out the requests (pseudo-code):
and then use with something like:
Note that this is psuedocode but hope it gives you an idea of how to manage things using objects and interface callbacks.
The text was updated successfully, but these errors were encountered: