#

API Docs for: 3.10.3
Show: Inherited Protected Private Deprecated

# State Class

Defined in: `attribute/js/State.js:1`
Module: attribute

The State class maintains state for a collection of named items, with a varying number of properties defined.

It avoids the need to create a separate class for the item, and separate instances of these classes for each item, by storing the state in a 2 level hash table, improving performance when the number of items is likely to be large.

## Constructor

### `State`

()

Defined in `attribute/js/State.js:1`

- Index
- Methods
- Properties

## Item Index

### Methods

- add
- addAll
- get
- getAll
- remove
- removeAll

### Properties

- data

## Methods

### `add`

(

- `name`
- `key`
- `val`

)

Defined in `attribute/js/State.js:22`

Adds a property to an item.

#### Parameters:

- `name` String

  The name of the item.

- `key` String

  The name of the property.

- `val` Any

  The value of the property.

### `addAll`

(

- `name`
- `obj`

)

Defined in `attribute/js/State.js:40`

Adds multiple properties to an item.

#### Parameters:

- `name` String

  The name of the item.

- `obj` Object

  A hash of property/value pairs.

### `get`

(

- `name`
- `key`

)
Any

Defined in `attribute/js/State.js:100`

For a given item, returns the value of the property requested, or undefined if not found.

#### Parameters:

- `name` String

  The name of the item

- `key` String

  Optional. The property value to retrieve.

#### Returns:

Any: The value of the supplied property.

### `getAll`

(

- `name`
- `reference`

)
Object

Defined in `attribute/js/State.js:116`

For the given item, returns an object with all of the item's property/value pairs. By default the object returned is a shallow copy of the stored data, but passing in true as the second parameter will return a reference to the stored data.

#### Parameters:

- `name` String

  The name of the item

- `reference` Boolean

  true, if you want a reference to the stored object

#### Returns:

Object: An object with property/value pairs for the item.

### `remove`

(

- `name`
- `key`

)

Defined in `attribute/js/State.js:62`

Removes a property from an item.

#### Parameters:

- `name` String

  The name of the item.

- `key` String

  The property to remove.

### `removeAll`

(

- `name`
- `obj`

)

Defined in `attribute/js/State.js:77`

Removes multiple properties from an item, or removes the item completely.

#### Parameters:

- `name` String

  The name of the item.

- `obj` Object | Array

  Collection of properties to delete. If not provided, the entire item is removed.

## Properties

### `data`

Unknown

Defined in `attribute/js/State.js:13`

Hash of attributes