EntitySpaces / entityspaces.js

A JavaScript Data Access Framework that uses Knockout
www.entityspaces.net
36 stars 11 forks source link

Automatically saving dirty objects to server #11

Open lucasjans opened 12 years ago

lucasjans commented 12 years ago

What's the best way to detect when an esEntity is dirty and automatically saving it to the server?

I've created a simple extension to monitor and changes and update them call save.

        ko.extenders.save = function (target, option) {
            debugger;
            target.subscribe(function (newValue) {
                console.log(option + ": " + newValue);
                option.save();
            });
            return target;
        };

And I can extend any object that is a column. Here's an example to save when the name is changed

this.Name = ko.observable().extend({save: this});

But what I would really like to do is extend the "isDirty." Problem is, by the time it exists, it's already returned to the viewModel. I would rather not have to dynamically for-each through the viewModel after the data is applied to extend it. Is there a better way?

When I look in here:

es.objects.RevCoCompanies.prototype.customize(function () {
\\etc...
});

isDirty still doesn't exist.

EntitySpaces commented 12 years ago

Our standard save method calls GetDirtyGraph() so only dirty entities are sent to the server during a call to Save.

EntitySpaces commented 12 years ago

Look at line 346 in this file (ignore the comment on line 345 I need to remove that as it is not slow) https://github.com/EntitySpaces/entityspaces.js/blob/master/Src/BaseClasses/EsEntityCollection.js

lucasjans commented 12 years ago

So how do I get notified of a dirty element on the graph? I can extend fields, but I can't extend isDirty.