diff
diff copied to clipboard
Allow Custom Accessor and Mutator Functions
I was wondering what the consensus was of adding an interface to provide the ability to use custom getters and setters? Possibly as an argument to applyChange or revertChange. This would be extremely useful in MVC frameworks like EmberJS which insist on using the provided accessors.
Act like I don't know anything about EmberJS. What would it look like?
EmberJS uses Ember.Object objects instead of POJOs (Plain Old JavaScript Objects). Mutating or accessing an Ember Object is done by using Ember.Object.set(keyName, value) or Ember.Object.get(keyName). This is done to make observers work and allow unknown properties to be resolved dynamically. This model is used not only in Ember but in Backbone, Knockout and other frameworks which seek to maximize compatibility.
The interface would look something like this.
observableDiff(lhs, rhs, function (d) {
applyChange(lhs, rhs, d, function(record) {
lhs.set(record.path, record.rhs);
});
});