-
Notifications
You must be signed in to change notification settings - Fork 1
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
FR: Events - pass in old data & and is_dirty
boolean
#7
Comments
+1 for this. |
As per discussion w/ Jesse in Discord, it would be even better if the event was only fired when there's changed/new data. |
Perhaps related: statamic/v2-hub#2520 |
It might be better, just a thought. Anyway, would like to see more practical examples of where you might actually use old data and/or dirty booleans in our data events? Providing old data to all of the events across our system could get messy. |
Like I said above Jesse, it's to prevent a loop. I'll try to find some code that I've used in the past. |
Theoretically, you'd be able to prevent loops by hooking into
(The |
How would I know to cancel the save if I don't know if anything has changed? So either we have to know if something has changed, or the event can't fire when nothing has changed. |
Not saying that is the solution, just adding context to the discussion around events. |
It's a lot simpler for Eloquent Models to check if they're dirty since they only have Perhaps the "saving" events are a better place for when you want to modify a thing. Then you don't have to re-save them. |
I only want to things if the content has been saved though...validation passed, all Statamic stuff done etc. |
This would be a very much appreciated addition! I've come across this a lot where I needed to check if a value has been changed or not. And only perform some logic when it did change. Right now I'm working around this with either some boolean values in the entry data or with some cache. But both feel very dirty and unreliable. |
A similar |
There have been several times where it's very useful for a listener to check the old version to see if anything has changed (dirty).
Reason for this is that sometimes you have to update the data and therefore call
$data->save()
, which fires the events again. This creates an infinite loop.I currently solve this by copying the core "save" code into my listener so the events aren't fired again.
Option would be able to call
save
with a "don't fire events" param? Or expose a deepersave
method that is only in charge of saving and not firing events?Any chance we could get that for v3?
The text was updated successfully, but these errors were encountered: