-
Notifications
You must be signed in to change notification settings - Fork 183
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
Dirty Tracking #386
Comments
Lets take these one at a time:
|
I think the biggest part of what @johnmeehan is suggesting is the |
@dnd because of the way that Reform works, you can access the xxx_was value simply by getting the model value. (Before sync/save obviously) such a method is necessary in AR because values of overwritten directly on the model instance, as we don't do that in Reform we've never seen the need to have a special method simply as an alias for model.attr ... |
@fran-worley yes, of course that is possible to do, but it feels like it is more of a workaround than anything. This seems like such a common operation, that having a more declarative way of doing it would lead to better code that more expresses the intent of what is happening. Also, as it stands you have to know the state of the form to use this method. If the model hasn't been sync'd, then this works just fine. If the model has been sync'd, then you have to use its methods. So now you can't just have one way of doing it, even though reform should easily be able to know and provide this information. Further, what if you're using reform with some type of ORM model, but also PORO models that don't implement any dirty tracking themselves. Basically if reform implements this functionality you can have one way of doing it no matter what the scenario. |
I don't mind one before- and after accessor in Disposable, but this is absolutely not code for a form, but must go to the update operation wrapping this. |
@dnd maybe I'm misunderstanding you. I don't see how accessing the form value vs the model value is a work around its kind the whole point of Reform. Even ActiveModel::Dirty requires some knowledge of state as once you're record is saved your changed? And other methods resent. I just worry about tagging on another round of methods to make Reform behave more like AR/AM when just tweaking your workflow to better embrace Reform might result in better code and a smaller gem. if you really really want a _was as an alias to call model.attr then it would end up in Reform-rails in a seperate module, but I'm really not convinced it's worth it. |
@fran-worley We can put this into Disposable into the Agreeing that this ain't no stinky Reform thing, though! |
It definitely wouldn't belong in reform-rails. Heck, I'm not even using Rails, and I need it. I think this aligns very much with the semantics of what one would expect from a form. The form should be able to tell me about the changes that are going to occur, not just that something changed. Given what Disposable is, and that it is already partially implemented there that is definitely the right place for the rest of the functionality though. The problem is mostly in the event of needing to do any dirty tracking after a Here's an example to try and demonstrate. # Using a Sequel model
user = User.create(name: 'tom')
form.validate(name: 'bob')
form.name => 'bob'
user.name => 'tom'
form.sync
form.name => 'bob'
user.name => 'bob'
# At this point you might say you could use the dirty tracking on the model
user.initial_value(:name) => 'tom'
# What about if you're using a PORO, that doesn't have any dirty tracking?
# It's the same scenario as above, but after the sync you have no option.
# Meaning if you use a PORO model, you have to then implement your own dirty
# tracking to be able to use it.
# If the form implements this functionality then it works no matter what is used, and
# what the current context of the form is.
form.name => 'bob'
form.initial_value(:name) => 'tom'
form.sync
form.name => 'bob'
form.initial_value(:name) => 'tom' |
@apotonick let’s move this to the disposable gem as you suggested |
RE: Dirty Tracking
I have a great big Reform Form that creates/updates a product that is composed of a number models. The form gathers dimensions for the different components that all change size depending on the overall size of the product.
Create action with Reform works fantasticly! Way better than the "Rails Way".
When editing these models with the form I need to update the dimensions ( and if I change one they all have to recalculate). Currently I have been using a
before_validation :recalculate_dimensions
call back in the models which will update the associated models if one of them is edited. It works but its messy.I wish to now extract this before_validation call back to a service object.
For dirty tracking Reform currently only has a
form.changed?(:title) #=> true
method.The code I am trying to pull out of the models is:
What am I getting at?
To me it looks like I am missing from the Active Model Dirty Tracking is the
xxx_was
andxxx_change
methods.@form.height_was
@form.height_change
Also discussed: #117
The text was updated successfully, but these errors were encountered: