-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
base: master
Are you sure you want to change the base?
Conversation
6951dd3
to
3af8371
Compare
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().
3af8371
to
7b2c2a7
Compare
* | ||
* @var callable[] | ||
*/ | ||
private $callbackStack = []; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()
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().