EmberTricks[0]: Force firing observers and listeners
Scenario:
You have a property or observer that just doesn't want to fire. In my case, we were using a separate controllers with one route to render modals. The modal was for editing some properties of a model with one catch, if I pressed cancel I wanted to rollback only changes for those properties and not the ones outside the modal. ~~model.rollback()~~
Requirements:
I want to listen to when the model changes so that is the approriate hook to observe.
Be able to clear forms on cancel and save
Be able to load current properties
Be able to do partial rollbacks on an unsaved model
Problems:
Listening on model means that it doesn't refire unless the model changes in some way
After pressing cancel and clearing the form it won't refire if you enter with the same model and forms and not pre populated
Binding directly to model properties will refire the the observers and properties but I will lose the ability to partially roll back a model.
Solution:
Create properties and observers that listen to model
Create proxy properties on the controller that hold the value for model
Set the model property to the proxy on save, clear on cancel
Set observers and properties to refire by calling this.propertyDidChange("model") after form is cleared.













