Class: Model

Model

A Model is a general-purpose, observable object, holding user specific data. The object can receive observer functions (via addObserver() function), which will be notified when the set( callback ) method of this object is called.

Constructor

new Model(nameopt)

Creates an instance of a Model.
Parameters:
Name Type Attributes Default Description
name String <optional>
--unnamed model-- A name for the model
Source:

Members

name :String

The name of the model.
Type:
  • String
Source:

observers

The set of observer functions to be called when this Model is changed via set() method.
Source:

Methods

addObserver(observer)

Adds an observer function to this Model.
Parameters:
Name Type Description
observer function The observer to add.
Source:
See:

notifyObservers(hintopt)

Invokes all observers.
Parameters:
Name Type Attributes Description
hint Object <optional>
An optional object to pass as argument to observers.
Source:

removeObserver(observer)

Removes an observer function from this Model.
The function will no longer be notified of changes in this Model.
Parameters:
Name Type Description
observer function The observer to be removed.
Source:

set(updater, hintopt)

Method to update the this Model.
A callback function is passed which is, typically, in charge to make changes in this object. When this callback returns, observers of this Model are notified.
Parameters:
Name Type Attributes Description
updater function The callback function in charge of changing this Model. The function will receive the reference to this Model as parameter.
hint Object <optional>
Any additional object to be passed to observers during notification.
Source:
Example
Model m = new Model('mymodel');
 m.set( () => { m.itemName='Tablet'; m.price=1200});