Class: BaseObject

saij/core/Object~BaseObject


import BaseObject from 'saij/core/Object';

Abstract base class; normally only used for creating subclasses and not instantiated in apps. Most non-trivial classes inherit from this.

This extends module:saij/core/Observable~Observable with observable properties, where each property is observable as well as the object as a whole.

Classes that inherit from this have pre-defined properties, to which you can add your owns. The pre-defined properties are listed in this documentation as 'Observable Properties', and have their own accessors; for example, module:saij/Engine~Engine has a target property, accessed with getTarget() and changed with setTarget(). Not all properties are however settable. There are also general-purpose accessors get() and set(). For example, get('target') is equivalent to getTarget().

The set accessors trigger a change event, and you can monitor this by registering a listener. For example, module:saij/Reactor~Reactor has an input property, so reactor.on('change:input', function(evt) {...}); would call the function whenever the value of the input property changes. Within the function, evt.target would be the Reactor, so evt.target.getInput() would return the new input.

You can add your own observable properties with object.set('prop', 'value'), and retrieve that with object.get('prop'). You can listen for changes on that property value with object.on('change:prop', listener). You can get a list of all properties with module:saij/Object~BaseObject#getProperties.

Note that the observable properties are separate from standard JS properties. You can, for example, give your map object a title with Engine.name='New name' and with Engine.set('title', 'Another title'). The first will be a hasOwnProperty; the second will appear in getProperties(). Only the second is observable.

Properties can be deleted by using the unset method. E.g. object.unset('foo').

new BaseObject(opt_values)

src/saij/core/Object.js, line 105
Name Type Description
values Object.<string, *>

An object with key-value pairs.

Fires:

Methods

get(key){*}

src/saij/core/Object.js, line 136

Gets a value.

Name Type Description
key string

Key name.

Returns:
Value.

getKeys(){Array.<string>}

src/saij/core/Object.js, line 148

Get a list of object property names.

Returns:
List of property names.

getProperties(){Object.<string, *>}

src/saij/core/Object.js, line 157

Get an object of all property names and values.

Returns:
Object.

set(key, value, opt_silent)

src/saij/core/Object.js, line 180

Sets a value.

Name Type Description
key string

Key name.

value *

Value.

silent boolean

Update without triggering an event.

setProperties(values, opt_silent)

src/saij/core/Object.js, line 199

Sets a collection of key-value pairs. Note that this changes any existing properties and adds new ones (it does not remove any existing properties).

Name Type Description
values Object.<string, *>

Values.

silent boolean

Update without triggering an event.

unset(key, opt_silent)

src/saij/core/Object.js, line 212

Unsets a property.

Name Type Description
key string

Key name.

silent boolean

Unset without triggering an event.