wes wes - 1 year ago 111
Javascript Question

breezejs: reject changes to specific property

Is it possible to reject the changes to a single property of a breeze object without rejecting ALL the changes to that object?

Say I have

// assume manager is an EntityManager containing a number of preexisting entities.
var person = manager.createEntity("Person");
// assume Name and House are valid properties of a Person object
person.Name("Jon Snow");

But I ONLY want to discard the changes made to the objects

Is this possible, if so, how would I go about doing it?

Note: I would rather not iterate of the
property and just replace them like that. I guess, I'm looking for a more graceful solution like...


is called on the property itself or something like that.

Answer Source

For the lack of a better solution I came up with the following code which seems to serve my purposes:

function RevertChangesToProperty(entity, propertyName) {
  if (entity.entityAspect.originalValues.hasOwnProperty(propertyName)) {
    var origValue = entity.entityAspect.originalValues[propertyName];

    entity.setProperty(propertyName, origValue);
    delete entity.entityAspect.originalValues[propertyName];

    if (Object.getOwnPropertyNames(entity.entityAspect.originalValues).length === 0) {

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download