Source code

CERNY.event.Revertable

This script provides a function Revertable to make an object revertable. Given a list of properties and their types (optional), it creates getters and setters for these properties. These setters will notify observers, whether the instance has been changed or reverted. Thus a Revertable is always an Observable.

Revertable should be called on the prototype of a constructor, see Observable for more information.

The object receives the methods set , get , commit , revert and hasChanged . set and get are called by the setters respectively getters, but can also be called directly.

The object will receive the property _revertableProperties on calling Revertable. On the first setter call, it will additionally receive the properties _revertableChangeCount and _revertableOriginal .

Provided type information, the setters and getters will receive a signature.

Used by

None

Functions

Revertable

Makes an object revertable.

The object will be able to keep track of its changed status, given that properties are set with the provided set method.

The properties which are of interest and contribute to the identity of the object must be passed to this function.

On setting values by the means of set the object will announce the events Revertable.EVT_CHANGE and Revertable.EVT_REVERT.

If type is ommited for a property by passing just the name of the property in the properties array, no signature will be defined on the getter and setter

obj (object) : the object to be made revertable
properties (Array) : an array of property names or objects with the properties 'name' and 'type'
commit

Commit the object. The current state becomes the original state.

hasChanged

Determine, if this object has changed.

return (boolean) : true, if the object has changed, false otherwise
revert

Revert the object to its orignial state.

History

2007-10-30 : Changed order of notification and setting in set.
2007-08-03 : Created.

API Documentation for version

2.0

Scripts

2.0

Functions

Support

If you have any question or suggestions regarding Cerny.js, do not hesitate to contact me. Your input is always welcome.