Adds a listener for data changes. If the listener was already added, nothing happens.
Callback to add
a function that can be called to remove the listener. It just calls removeChangeListener with aCallback.
Adds a listener for changes to a certain property. If the listener was already added for the property, nothing happens.
Name of property
Callback function to call when property changes value
a function that can be called to remove the listener. It just calls removePropertyChangeListener with aProperty and aListener.
Protected
addAdds a validator for a certain property.
Property name
A validator for a value or property
Protected
changedThis method can be called when a property changes value. If the instance is locked via lock the names are stored. Else the onPropertiesChanged method is called with the list of names.
The function accepts a variable number of name parameters
One or more property names that changed
Clears the dirty state.
Gets all dirty properties.
a list of dirty property names.
Gets a value of a property. The method checks if the property is a function. If it is, the method returns the result of a call to that function. Else the method just returns the value.
Name of property
Value of property
Protected
getProtected
A helper method that calls getStoredStringProperty and converts the result to a boolean typed value.
Key to get value from the storage with
Default value to use if no stored value could be found
Either the stored value or aDefault
Protected
getProtected
A helper method that calls getStoredStringProperty and converts the result to a
number typed value by using parseFloat
.
Key to get value from the storage with
Default value to use if no stored value could be found
Either the stored value or aDefault
Protected
getProtected
A helper method that calls getStoredStringProperty and converts the result to a
number typed value by using parseInt
.
Key to get value from the storage with
Default value to use if no stored value could be found
Either the stored value or aDefault
Protected
getProtected
This method just calls getValueFromStorage.
Key to get value from the storage with
Default value to use if no stored value could be found
Protected
getProtected
This method gets the value from a persistent storage.
The default implementation uses the window.localStorage
.
Key to get value for.
Default value that is returned if there is no stored value available.
The stored value or aDefault
Checks if there are changed properties. This method only is useful while the data is locked. Else the method will always return false.
true if there is a changed property.
Checks if there are dirty properties.
true if there is a dirty property.
Protected
onThis method is called whenever changed is called or the data structure is unlocked and there are changed properties.
The default implementation invokes all the registered listeners. Subclasses can override this method to take additional actions.
List of property names
Protected
processProtected
Processes a possible property assignment. If aNewValue is not undefined, compare it to the current value and when not equal call changed for the property.
When anEqualFunction is not defined, the method uses ===.
The aTransformFunction can be used for example to keep a value within a certain range.
Property name
Current value of the property
New value of the property or undefined if no new value needs to be set
Function that is called to set the new changed value (if any)
Optional
aTransformFunction: (value: T) => TFunction to transform aNewValue with before comparing and assigning it
Optional
anEqualFunction: (value0: T, value1: T) => booleanCustom compare function that should return true if objects are equal. When null, the method uses === to compare the values.
the current or new property value
Removes a listener for data changes.
Callback to remove
Removes a listener for changes to a certain property.
Name of property
Listener to remove
Sets a property to a value. The method checks if the property is a function. If it is, the method will call the function passing the value as parameter. Else the method will assign the value directly and call changed.
Property name
Value to assign
Protected
setProtected
A helper method that calls setStoredStringProperty with either '0' or '1'.
Property to store value for
Key to use for the storage to store the value for
Value to store
Protected
setProtected
A helper method that calls setStoredStringProperty with a text version of the number value.
Property to store value for
Key to use for the storage to store the value for
Value to store
Protected
setProtected
A helper method that calls setStoredStringProperty with a text version of the number value.
Property to store value for
Key to use for the storage to store the value for
Value to store
Protected
setProtected
This method calls processPropertyValue to store the value using setValueInStorage.
Property to store value for
Key to use for the storage to store the value for
Value to store
Protected
setProtected
This method stores a value for a certain key in some persistent storage.
The default implementation uses window.localStorage
.
Key to store value for
Value to store
Unlocks the model instance. If a call matches the first call to lock, call onPropertiesChanged if there are any pending changes.
current lock count
UFStorableModel adds methods to support storing and retrieving properties from a persistent storage.
The default implementation uses
window.localStorage
. Subclasses can override setValueInStorage and getValueFromStorage to use a different persistent storage solution.