The initial state of the object.
Optional
options: SyncStateOptionsOptional configuration options.
Private
_conditionallyPrivate
_setAppends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.
The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.
When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.
When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.
When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.
If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.
The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.
Optional
options: boolean | AddEventListenerOptionsDeletes a path from the state.
The path to delete.
Optional
update: boolean = trueWhether to dispatch events.
Dispatches an event.
The type of the event payload.
The type of the event.
Optional
payload: PayloadThe event payload.
Ensures that a path exists in the state.
Extends the current instance with a new method.
The name of the new property.
The new method.
Rest
...args: any[]import { ReactiumSyncState, useSyncState } from '@atomic-reactor/reactium-sdk-core';
import React from 'react';
// Define a type that includes the extension
type MySyncStateType = ReactiumSyncState<{ value: number }> & {
increment: () => void;
};
const MyComponent = () => {
const state = useSyncState({ value: 0 }) as MySyncStateType;
// now state.increment can be called (with type safety)
state.extend('increment', () => state.set('value', state.get('value', 0) + 1));
return (
<div>
<div>{state.get('value')}</div>
<button onClick={state.increment}>
Increment
</button>
</div>
);
};
useSyncState for how to create a new instance.
Retrieves a value from the state.
The path of the value to retrieve.
Optional
defaultValue: anyThe default value to return if the path does not exist.
The value at the specified path, or the default value if the path does not exist.
Inserts a value at a specific index in an array located at the given path.
The path to the array in the state where the value should be inserted.
The value to insert.
The index at which to insert the value.
Optional
update: boolean = trueWhether to dispatch update events. If true, 'before-insert', 'insert', and 'change' events will be dispatched as appropriate.
Will throw an error if trying to insert into the root state.
Private
notResets the state to the initial state.
Sets the entire state to a new value.
The type of the value. Defaults to StateType
if not provided.
This parameter is not used.
Optional
update: booleanWhether to dispatch events.
Optional
forceMerge: booleanWhether to force a merge of the value.
Replaces the entire state with a new value.
The type of the value. Defaults to StateType
if not provided.
Indicates that the entire state should be replaced.
Optional
update: booleanWhether to dispatch events.
Optional
forceMerge: booleanWhether to force a merge of the value.
Sets a value at a specific path in the state.
The path to set the value at.
The value to set.
Optional
update: booleanWhether to dispatch events.
Optional
forceMerge: booleanWhether to force a merge of the value.
Creates a new instance of the ReactiumSyncState class.