Class: Model

stb/model~ Model

new Model(dataopt)

Base model implementation.

Represents domain-specific data or information that an application will be working with. A typical example is a user account (e.g name, avatar, e-mail) or a music track (e.g title, year, album). Holds information, but don’t handle behaviour and don’t format information or influence how data appears.

Parameters:
Name Type Attributes Default Description
data Object <optional>
{}

init attributes

Source:

Extends

  • Emitter

Members

data :Object.<string, *>

Model attributes with given data or empty hash table.

Type:
  • Object.<string, *>
Source:

Methods

clear() → {boolean}

Remove all attributes from the model.

Source:
Fires:
Returns:

operation status

Type
boolean

get(name) → {*}

Get the model attribute by name.

Parameters:
Name Type Description
name string

attribute

Source:
Returns:

associated value

Type
*

has(name) → {boolean}

Check an attribute existence.

Parameters:
Name Type Description
name string

attribute

Source:
Returns:

attribute exists or not

Type
boolean

init(data) → {boolean}

Clear and set model data.

Parameters:
Name Type Description
data Object

attributes

Source:
Fires:
Returns:

operation status

Type
boolean

set(name, value) → {boolean}

Update or create a model attribute.

Parameters:
Name Type Description
name string

attribute

value *

associated value

Source:
Fires:
Returns:

operation status (true - attribute value was changed/created)

Type
boolean

unset(name) → {boolean}

Delete the given attribute by name.

Parameters:
Name Type Description
name string

attribute

Source:
Fires:
Returns:

operation status (true - attribute was deleted)

Type
boolean

Events

change

Update or create a model attribute event.

Type:
  • Object
Properties:
Name Type Attributes Description
name string

attribute name

prev * <optional>

old/previous attribute value (can be absent on attribute creation)

curr * <optional>

new/current attribute value (can be absent on attribute removal)

Source:

clear

Remove all attributes from the model event.

Type:
  • Object
Properties:
Name Type Description
data Object

old model attributes

Source:

init

Set model data event.

Type:
  • Object
Properties:
Name Type Description
data Object

new model attributes

Source: