Skip to content
New issue

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

Fix long standing bug where load* functions could not use callbacks in preload() #956

Merged
merged 11 commits into from
Oct 4, 2015

Conversation

Jared-Sprague
Copy link
Contributor

Issue: #949

The problem was that the decrementPreload() function was getting pushed on the argument list for load functions in _wrapPreload() and when no success callback was passed to the load function decrementCallback() was assumed to be in the position of the success callback, but when a callback was passed in, decrementPreload would never get called.

@Jared-Sprague Jared-Sprague changed the title Fix bug where load* functions could not use callbacks in preload() Fix long standing bug where load* functions could not use callbacks in preload() Oct 1, 2015
@Jared-Sprague
Copy link
Contributor Author

@lmccart This pull request includes unit tests and an example to demonstrate that it works

@lmccart
Copy link
Member

lmccart commented Oct 4, 2015

hey @Jared-Sprague thanks for this! this definitely fixes the problem, but I feel a little unsure about repeating the same code lines in every function. is there a way to do this in just one place? either somewhere around here where preload is handled, or by making helper methods that get called in each loadX() function?

@Jared-Sprague
Copy link
Contributor Author

@lmccart I don't think there is a way to fix this without modifying each load function, because decrementCallback has to be called inside the load function when in preload, it just used to be called in the place of the success callback. However I totally can extract the common lines from each load function into a helper method. I'll do that now!

@Jared-Sprague
Copy link
Contributor Author

@lmccart Ok check my last commit diff and let me know what you think!

@lmccart
Copy link
Member

lmccart commented Oct 4, 2015

if (typeof decrementPreload === 'function')

this looks great. one super nitpicky suggestion, would it make sense to put this above check inside the _getDecrementPreload() function, so that function either returns a pointer to the decrement callback function or null? then you could just check in the individual functions if (decrementPreload). does that seem right?

@Jared-Sprague
Copy link
Contributor Author

@lmccart sounds fine to me! Stay tuned that will only take a minute.

@Jared-Sprague
Copy link
Contributor Author

@lmccart Ok check it out. Note, I still have to check that (callback !== decrementPreload) because when no callback is passed in decrementPreload will be in the callback position and we don't want to call decrementPreload twice.

@lmccart
Copy link
Member

lmccart commented Oct 4, 2015

great, thank you!

lmccart pushed a commit that referenced this pull request Oct 4, 2015
Fix long standing bug where load* functions could not use callbacks in preload()
@lmccart lmccart merged commit e53731c into processing:master Oct 4, 2015
@Jared-Sprague
Copy link
Contributor Author

@lmccart whoo hoo! Thank you too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants