# Class Consumable<T>

A class that holds a value. Listeners can be attached and whenever a new value is dispatched, the listeners are called.

#### See

https://github.com/nombrekeff/cardboard-js/wiki/Consumables

#### Type Parameters

- #### T = any

#### Hierarchy

- CEvent<T>
  - Consumable

#### Implements

- IConsumable<T>

- Defined in consumables.ts:10

#####
Index

### Constructors

constructor

### Properties

_destroyer?
_listeners
_value

### Accessors

value

### Methods

changed
destroy
dispatch
intersect
listen
remove
toString
valueOf

## Constructors

### constructor

- new Consumable<T>(val, destroyer?): Consumable<T>

- #### Type Parameters

  - #### T = any

  #### Parameters

  - ##### val: T

  - ##### `Optional` destroyer: (() => void)

    - - (): void

      - #### Returns void

  #### Returns Consumable<T>

  Overrides CEvent.constructor

  - Defined in consumables.ts:23

## Properties

### `Private` `Optional` `Readonly` _destroyer

_destroyer?: (() => void)

#### Type declaration

- - (): void

  - #### Returns void

- Defined in consumables.ts:12

### `Protected` _listeners

_listeners: ((data) => void)[] = []

#### Type declaration

- - (data): void

  - #### Parameters

    - ##### data: undefined | T

    #### Returns void

Inherited from CEvent._listeners

- Defined in events.ts:15

### `Private` _value

_value: T

- Defined in consumables.ts:11

## Accessors

### value

- get value(): T

- #### Returns T

  Implementation of IConsumable.value

  - Defined in consumables.ts:14
- set value(val): void

- Set the value, and dispatch to all listeners.

  #### Parameters

  - ##### val: T

  #### Returns void

  Implementation of IConsumable.value

  - Defined in consumables.ts:19

## Methods

### changed

- changed(callback): Consumable<T>

- Add a listener for when this Consumable changes.

  #### Parameters

  - ##### callback: ((val) => void)

    - - (val): void

      - #### Parameters

        - ##### val: T

        #### Returns void

  #### Returns Consumable<T>

  Implementation of IConsumable.changed

  - Defined in consumables.ts:61

### destroy

- destroy(): void

- #### Returns void

  Implementation of IConsumable.destroy

  Overrides CEvent.destroy

  - Defined in consumables.ts:87

### dispatch

- dispatch(val): Consumable<T>

- Set's the new value, and calls all the listeners. You can additionaly set the value directly.

  #### Parameters

  - ##### val: T

  #### Returns Consumable<T>

  Implementation of IConsumable.dispatch

  Overrides CEvent.dispatch

  - Defined in consumables.ts:78

### intersect

- intersect<K>(intersector): any

- Create a new Consumable that intersects this Consumable. The new Consumable updates its value based on this Consumable.

  #### Type Parameters

  - #### K

  #### Parameters

  - ##### intersector: ((val) => K)

    - - (val): K

      - #### Parameters

        - ##### val: T

        #### Returns K

  #### Returns any

  #### Example

      const value = createConsumable(2);
      const isGreater = value.intersect((value) => value > 5);
      // > isGreater == false;
      value.dispatch(6);
      // > isGreater == true;

  Implementation of IConsumable.intersect

  - Defined in consumables.ts:106

### listen

- listen(fn): void

- #### Parameters

  - ##### fn: ((data?) => void)

    - - (data?): void

      - #### Parameters

        - ##### `Optional` data: T

        #### Returns void

  Inherited from CEvent.listen

  - Defined in events.ts:17

### remove

- remove(callback): Consumable<T>

- Remove a listener for when this Consumable changes.

  #### Parameters

  - ##### callback: ((val) => void)

    - - (val): void

      - #### Parameters

        - ##### val: T

        #### Returns void

  #### Returns Consumable<T>

  Implementation of IConsumable.remove

  Overrides CEvent.remove

  - Defined in consumables.ts:69

### toString

- toString(): any

- #### Returns any

  - Defined in consumables.ts:54

### valueOf

- valueOf(): T

- #### Returns T

  - Defined in consumables.ts:50

Generated using TypeDoc