UFModel implements IUFModel and adds support change events and dirty state.

Implements

Constructors

Methods

  • Adds a listener for changes to a certain property. If the listener was already added for the property, nothing happens.

    Parameters

    Returns UFCallback

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

  • 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

    • Rest ...aNames: string[]

      One or more property names that changed

    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

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

  • Checks if a value is valid for a property.

    If the property is unknown or does not have any validator attached to it, the method returns true.

    Parameters

    • aPropertyName: string

      Property name

    • aValue: any

      Value to test

    Returns boolean

    True if the value is valid for property, otherwise false.

  • 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) => void)

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

        • (value): void
        • Parameters

          • value: T

          Returns void

    • Optional aTransformFunction: ((value) => T)

      Function to transform aNewValue with before comparing and assigning it

        • (value): T
        • Parameters

          • value: T

          Returns T

    • Optional anEqualFunction: ((value0, value1) => boolean)

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

        • (value0, value1): boolean
        • Parameters

          • value0: T
          • value1: T

          Returns boolean

    Returns T

    the current or new property value

  • Removes a listener for changes to a certain property.

    Parameters

    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