getoutreach / epf

A framework for keeping your Ember.js apps in sync.
http://epf.io
MIT License
369 stars 33 forks source link

isDirty not updated? #104

Closed miguelcobain closed 10 years ago

miguelcobain commented 10 years ago

I'm having some trouble with the isDirty flag.

When I used ED I used to have a conditional check in my templates that depended on isDirty. Something like:

{{#if isDirty}}
    <!-- render some save and cancel controls here -->
{{/if}}

As soon as I changed any property in the model, this conditional block would get immediatly rendered. But with EPF this doesn't happen. isDirty seems to change its value, but the observers don't fire. For debugging I dropped an observer in my model like:

App.MyModel = Ep.Model.extend({
    // some model attributes
    dirtyDidChange:function(){
        this.get('isDirty');
        console.log('isDirty changed: ',isDirty);
    }.observes('isDirty')
});

But this never gets executed. Does this have anything to do with the isDirty computed property being volatile? What is happening?

Thanks!

ghempton commented 10 years ago

Yes this is most likely having to do with isDirty being volatile. The reason for this is that dirtiness is somewhat expensive to compute (as the properties could change back to their original values and not be dirty anymore). I think there is still a solution here, however. Let me think about this.

miguelcobain commented 10 years ago

It may be expensive, but remember:

Correctness is paramount. All other features, including performance, are important, but secondary.

:)

Just kidding. Of course we need to make a good balance between both things. This is a very useful feature.

How does ED tackle this?

miguelcobain commented 10 years ago

Meanwhile we can cyclically check the isDirty property with an interval. But that's such a dirty hack...

jimsynz commented 10 years ago

I just ran into exactly this problem myself. For now I'm just going to hack together my own isDirty on the controller because I kind of need it.

ghempton commented 10 years ago

I just checked in a commit to make model.isDirty no longer volatile. This should fix your issue (let me know if it doesn't). I also added session.isDirty.