2
votes

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");
person.House("Lannister");

But I ONLY want to discard the changes made to the objects House property.

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

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

person.House.rejectChanges();

where rejectChanges() is called on the property itself or something like that.

2

2 Answers

2
votes

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) {
      entity.entityAspect.setUnchanged();
    }
  }
}
1
votes

If person.House property has an entityAspect, you can call rejectChanges() on this property's entityAspect. Property has an entityAspect if it is an object, that has other properties. Simple type like string or Int does not have entityAspect, properties of simple type just belong to another object

person.House.entityAspect.rejectChanges()