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.

Hierarchy

  • UFModel
    • UFStorableModel

Constructors

Methods

  • Adds a listener for data changes. If the listener was already added, nothing happens.

    Parameters

    • aCallback: UFModelChangedCallback

      Callback to add

    Returns UFCallback

    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.

    Parameters

    • aProperty: string

      Name of property

    • aListener: UFPropertyChangedCallback

      Callback function to call when property changes value

    Returns UFCallback

    a function that can be called to remove the listener. It just calls removePropertyChangeListener with aProperty and aListener.

  • Adds a validator for a certain property.

    Parameters

    • aPropertyName: string

      Property name

    • aValidator: IUFValidateValue | IUFValueValidator | IUFPropertyValidator

      A validator for a value or property

    Returns void

  • This 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

    Parameters

    • ...aNames: string[]

      One or more property names that changed

    Returns void

  • Clears the dirty state.

    Returns void

  • Gets all dirty properties.

    Returns string[]

    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.

    Type Parameters

    • T

    Parameters

    • aName: string

      Name of property

    Returns T

    Value of property

  • Protected

    A helper method that calls getStoredStringProperty and converts the result to a boolean typed value.

    Parameters

    • aKey: string

      Key to get value from the storage with

    • aDefault: boolean

      Default value to use if no stored value could be found

    Returns boolean

    Either the stored value or aDefault

  • Protected

    A helper method that calls getStoredStringProperty and converts the result to a number typed value by using parseFloat.

    Parameters

    • aKey: string

      Key to get value from the storage with

    • aDefault: number

      Default value to use if no stored value could be found

    Returns number

    Either the stored value or aDefault

  • Protected

    A helper method that calls getStoredStringProperty and converts the result to a number typed value by using parseInt.

    Parameters

    • aKey: string

      Key to get value from the storage with

    • aDefault: number

      Default value to use if no stored value could be found

    Returns number

    Either the stored value or aDefault

  • Protected

    This method just calls getValueFromStorage.

    Parameters

    • aKey: string

      Key to get value from the storage with

    • aDefault: string

      Default value to use if no stored value could be found

    Returns string

  • Protected

    This method gets the value from a persistent storage.

    The default implementation uses the window.localStorage.

    Parameters

    • aKey: string

      Key to get value for.

    • aDefault: string

      Default value that is returned if there is no stored value available.

    Returns string

    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.

    Returns boolean

    true if there is a changed property.

  • Checks if there are dirty properties.

    Returns boolean

    true if there is a dirty property.

  • Parameters

    • aPropertyName: string
    • aValue: any

    Returns boolean

  • Locks the model instance, preventing changed events from being fired. An internal lock counter is kept; so the number of lock and unlock calls must match before the model instance is fully unlocked.

    Returns number

    current lock count

  • This 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.

    Parameters

    • aList: string[]

      List of property names

    Returns void

  • Protected

    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.

    Type Parameters

    • T

    Parameters

    • aName: string

      Property name

    • aCurrentValue: T

      Current value of the property

    • aNewValue: T

      New value of the property or undefined if no new value needs to be set

    • aSetterFunction: (value: T) => void

      Function that is called to set the new changed value (if any)

    • OptionalaTransformFunction: (value: T) => T

      Function to transform aNewValue with before comparing and assigning it

    • OptionalanEqualFunction: (value0: T, value1: T) => boolean

      Custom compare function that should return true if objects are equal. When null, the method uses === to compare the values.

    Returns T

    the current or new property value

  • Removes a listener for data changes.

    Parameters

    • aCallback: UFModelChangedCallback

      Callback to remove

    Returns void

  • Removes a listener for changes to a certain property.

    Parameters

    • aProperty: string

      Name of property

    • aListener: UFPropertyChangedCallback

      Listener to remove

    Returns void

  • 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.

    Type Parameters

    • T

    Parameters

    • aName: string

      Property name

    • aValue: T

      Value to assign

    Returns void

  • Protected

    A helper method that calls setStoredStringProperty with either '0' or '1'.

    Parameters

    • aPropertyName: string

      Property to store value for

    • aKey: string

      Key to use for the storage to store the value for

    • aValue: boolean

      Value to store

    Returns void

  • Protected

    A helper method that calls setStoredStringProperty with a text version of the number value.

    Parameters

    • aPropertyName: string

      Property to store value for

    • aKey: string

      Key to use for the storage to store the value for

    • aValue: number

      Value to store

    Returns void

  • Protected

    A helper method that calls setStoredStringProperty with a text version of the number value.

    Parameters

    • aPropertyName: string

      Property to store value for

    • aKey: string

      Key to use for the storage to store the value for

    • aValue: number

      Value to store

    Returns void

  • Protected

    This method calls processPropertyValue to store the value using setValueInStorage.

    Parameters

    • aPropertyName: string

      Property to store value for

    • aKey: string

      Key to use for the storage to store the value for

    • aValue: string

      Value to store

    Returns void

  • Protected

    This method stores a value for a certain key in some persistent storage.

    The default implementation uses window.localStorage.

    Parameters

    • aKey: string

      Key to store value for

    • aValue: string

      Value to store

    Returns void

  • Unlocks the model instance. If a call matches the first call to lock, call onPropertiesChanged if there are any pending changes.

    Returns number

    current lock count