Class: MemoryModel

system.models. MemoryModel


new MemoryModel()

This model can keep an object in memory and emit messages if this object is changing.

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

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

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

var model = new MemoryModel();

model.beforeChanged.connect( beforeChanged ) ;
model.changed.connect( changed ) ;
model.cleared.connect( cleared ) ;

trace( "-- history" ) ;

model.current = "home" ;
model.current = "near" ;
model.current = "search" ;
model.current = "place" ;
model.current = "events" ;
model.current = "map" ;
model.current = "test" ;

trace( "-- back" ) ;

trace( "back() : " + model.back() ) ;

trace( "-- backTo(3)" ) ;

trace( "backTo(3) : " + model.backTo( 3 ) ) ;

trace( "-- home" ) ;

trace( 'home() : ' + model.home() ) ;

trace( "--" ) ;

model.clear() ;

Extends

Members


<static> this.element

The element of this entry.


<static> this.next

The next entry.


<static> this.previous

The previous entry.


<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 selected value in this model.

Overrides:

enableErrorChecking :boolean

Indicates if the model throws errors.

Type:
  • boolean
Default Value:
  • false

<readonly> length

Indicates the number of elements in memory model.


<readonly> reduced

Indicates in the beforeChange signal if the model is reduced (use the back or the backTo method). This property is true only before the change of the new position in the model.


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

Methods


back()

Go back in the memory and removes the last element in the memory model.

Returns:

The last removed element in the memory.


backTo( [pos])

Go back in the memory and removes the all the element in the memory model to a specific position.

Parameters:
Name Type Argument Default Description
pos number <optional>
1

The position to back in memory.

Returns:

The last removed element in the memory.


clear()

Clear the model.

Overrides:

first()

Returns the first element in memory.

Throws:

NoSuchElementError if this list is empty.

Returns:

the first element in this list.


home()

Go home, select the first element in the memory and remove all other elements. This method work only if the memory length is greater than 1.

Returns:

The last removed element in the memory.


isEmpty()

Returns true if this memory model is empty.

Returns:

true if this memory model is empty.


last()

Returns the last element in memory.

Throws:

NoSuchElementError if this list is empty.

Returns:

the last element in this list.


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: