Class: MapModel

system.models.maps. MapModel


new MapModel()

This model use an internal KeyValuePair map to register objects.

Implements:
Example
var o1 = { id : "key1" } ;
var o2 = { id : "key2" } ;
var o3 = { id : "key3" } ;
var o4 = { id : "key1" } ;

var added = function( entry , model )
{
    trace( "[+] added entry:" + dump(entry) + " size:" + model.length ) ;
}

var beforeChanged = function( entry , model )
{
    trace( "[--] before:" + dump(entry) + " current:" + model.current + " size:" + model.length ) ;
}

var changed = function( entry , model )
{
    trace( "[++] change:" + dump(entry) + " current:" + model.current + " size:" + model.length ) ;
}

var cleared = function( model )
{
    trace( "[x] clear current:" + model.current + " size:" + model.length ) ;
}

var removed = function( entry , model )
{
    trace( "[-] removed entry:" + dump(entry) + " size:" + model.length ) ;
}

var updated = function( entry , model )
{
    trace( "[u] update entry:" + dump(entry) + " size:" + model.length ) ;
}

var model = new MapModel() ;

model.added.connect( added ) ;
model.beforeChanged.connect( beforeChanged ) ;
model.changed.connect( changed ) ;
model.cleared.connect( cleared ) ;
model.removed.connect( removed ) ;
model.updated.connect( updated ) ;

model.add( o1 ) ;
model.add( o2 ) ;
model.add( o3 ) ;

trace( "#  model.get('key1') == o1 : " + ( model.get("key1") === o1 ) ) ;
trace( "#  model.get('key1') == o4 : " + ( model.get("key1") === o4 ) ) ;

model.update( o4 ) ;

model.current = o1 ;
model.current = o2 ;

Extends

Members


<static, constant> DEFAULT_PRIMARY_KEY :string

Indicates the default primary key value ("id").

Type:
  • string
Default Value:
  • "id"

<constant> added :system.signals.Signal

Emits a message when an entry is added in the model.

Type:

<constant> beforeChanged :system.signals.Signal

Emits a message before the current object in the model is changed.

Type:
Inherited From:

<constant> changed :system.signals.Signal

Emits a message when the current object in the model is changed.

Type:
Inherited From:

<constant> cleared :system.signals.Signal

Emits a message when the current object in the model is cleared.

Type:
Inherited From:

current

Determinates the current selected value in this model.

Inherited From:

<readonly> length :number

Indicates the number of elements register in the model.

Type:
  • number

primaryKey

Indicates the name of the primary key used to map all objects in the model and identifies each record in the table. By default the model use the "id" primary key in the objects.

Note: If you use this property and if the model contains entries, all entries will be removing.

See:
  • MapModel.DEFAULT_PRIMARY_KEY

<constant> removed :system.signals.Signal

Emits a message when an entry is removed in the model.

Type:

security :boolean

This property defined if the current property can accept the same object in argument as the current one.

Type:
  • boolean
Inherited From:
Default Value:
  • true

<constant> updated :system.signals.Signal

Emits a message when an entry is updated in the model.

Type:

Methods


add(key)

Returns the entry defined by the key passed-in argument.

Parameters:
Name Type Description
key *

The key to search a specific entry in the model.

Returns:

The entry defined by the key passed-in argument.


add(entry)

Inserts an entry in the model, must be identifiable and contains an id property.

Parameters:
Name Type Description
entry system.data.Identifiable

The identifiable object to register in the model.

Throws:
  • ReferenceError if the argument of this method is 'null' or 'undefined'.

  • ReferenceError if the passed-in entry is already register in the model.


clear()

Removes all entries register in the model.

Overrides:

getByProperty()

Returns an entry defines in the model with the specified member.

Returns:

an entry defines in the model with the specified member.


has(entry)

Returns true if the model contains the specified entry.

Parameters:
Name Type Description
entry system.data.Identifiable

The entry reference to verify.

Returns:

true if the model contains the specified entry.


hasByProperty()

Returns true if the model contains the specified attribute value.

Returns:

true if the model contains the specified key in argument


hasKey()

Returns true if the model contains the specified id key in argument.

Returns:

true if the model contains the specified id key in argument


isEmpty()

Returns true if this model is empty.

Returns:

true if this model is empty.


iterator()

Returns the iterator of this model.

Returns:

the iterator of this model.


keyIterator()

Returns the keys iterator of this model.

Returns:

the keys iterator of this model.


notifyAdd()

Notify a signal when a new entry is inserted in the model.


notifyBeforeChange()

Notify a signal before the specified value is changed.

Inherited From:

notifyChange()

Notify a signal when the model is changed.

Inherited From:

notifyClear()

Notify a signal when the model is cleared.

Inherited From:

notifyRemove()

Notify a signal when a new entry is removed in the model.


notifyUpdate()

Notify a signal when a new entry is updated in the model.


remove()

Removes an entry in the model.


setMap(map)

Enforce to set the internal KeyValuePair collection of this model (default use a new Array instance). This method change the model without notification.

Parameters:
Name Type Description
map system.data.KeyValuePair

The map reference to initialize this model.


update()

Returns the internal KeyValuePair (map) representation of this model.

Returns:

The internal KeyValuePair (map) representation of this model.


update(entry)

Update an entry in the model.

Parameters:
Name Type Description
entry system.data.Identifiable

The new value to insert in the model with a specific id.