setDataProperty() to undefine / remove a property

Hi,

I’m trying to remove a property from an object that is within my model (associated with a port). I use model.setDataProperty(object, propertyName, newvalue) to update such values, but in this case I wish for propertyName to be removed from object altogether, and to have this modification be subject to the undo machinery. What is the proper way to accomplish this?

Thanks,

-Luddy

Use undefined as the new value.

GoJS models and bindings do not distinguish when a property does not exist on an object and when a property does exist but the value is undefined, so if you really need to delete the property rather than set it to undefined, I’m not sure there’s a good simple solution. Maybe via side effect a property setter could remove itself?

OK, I think that will work. I’ll make any code of my own that manipulates that model data do the same – treat undefined and no such property as identical conditions.

[edit: Another possibility for anyone looking to do this is to use setDataProperty on the containing object, and replace it with a copy of the original, with the particular property deleted.]

Thanks,

-Luddy