Skip to content

Dispatcher API

David A. Sanders edited this page Dec 14, 2020 · 3 revisions

The TrebleGSM SubscribeAPI was introduced in V2 to access and manage state in the Store.

You can access the SubscribeAPI object with the useTreble hook.

const [StoreItems, StoreMethods] = useTreble();

Store.update

This method is used to update a state value in the Store with a new value.

Store.update(action, dispatchValue, options?);

Store.edit

Update a single object in a state object array. Uses the trebleKey property to find the object and replace it with the updated one. (Must have the Keys feature set to true in the Store)

Store.edit(action, updatedStateObject);

Store.remove

Targets a value in a Store state array and removes it.

Store.remove(action, targetValue);

Store.removeBatch

Removes an array of values from a Store state array.

Store.removeBatch(action, targetBatch);

Store.append

Appends a state value to a Store state array.

Store.append(action, dispatchValue, options?);

Store.prepend

Prepends a state value to a Store state array.

Store.prepend(action: string, dispatchValue, options?);

Store.orderBy

Orders a target property in ascending or descending order.

Store.orderBy(action, targetProperty, orderType: 'asc' | 'desc');

Store.toggle

Takes the current boolean state of a Store state object and toggles boolean values back and forth.

Store.toggle(action, currentState);

Store.reset

Takes a state action and then resets the store value to its initial value.

Store.reset(action);

Store.getActions

Returns an array of all Store actions.

Store.getActions();

Store.getStateKeys

Returns an array of all Store state keys.

Store.getStateKeys();