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

Add addCallback() method #474

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jesse-r-s-hines
Copy link

setCallback() replaces previous callbacks making you have to repeat any
logic in the "base case' definition callback if you have a callback on
one of the groups. This commit adds an addCallback() method which can
be used to add a callback while still letting earlier callbacks be called
as well.

addCallback() will add the callback to a stack, and then all of the callbacks
will be called when creating the object. If any of the callbacks return false
the model won't be persisted a second time.

Calling setCallback() after addCallback() will clear the callback stack
before it sets the new callback. This will maintain backwards compatibility
with the previous behavior of setCallback().

setCallback() replaces previous callbacks making you have to repeat any
logic in the "base case' definition callback if you have a callback on
one of the groups. This commit adds an addCallback() method which can
be used to add a callback while still letting earlier callbacks be called
as well.

addCallback() will add the callback to a stack, and then all of the callbacks
will be called when creating the object. If any of the callbacks return false
the model won't be persisted a second time.

Calling setCallback() after addCallback() will clear the callback stack
before it sets the new callback. This will maintain backwards compatibility
with the previous behavior of setCallback().
*
* @var callable[]
*/
private $callbackStack = [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this as well as a callback variable. Can we remove the callback property?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need both, I used the callback property to avoid recreating the lambda on every getCallback(). That may be premature optimization though.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed the callback field and just used callbackStack directly in getCallback()

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.

None yet

2 participants