Skip to content

ThingAdapter

Defined in: index.ts:35

thi.ng/atom adapter — backs state with @thi.ng/atom’s Atom<T>. When options.history is set, the atom is wrapped in History and the adapter exposes undo / redo / canUndo / canRedo / clearHistory.

Returned by createThingStoreSync / createThingStore as the concrete adapter type so consumers can access undo/redo without a cast. Still implements Store<T> — works anywhere the other adapters do.

Type ParameterDefault type
TStateany
  • Store<TState>

new ThingAdapter<TState>(initialState, options?): ThingAdapter<TState>

Defined in: index.ts:42

ParameterType
initialStateTState
options?ThingAdapterOptions

ThingAdapter<TState>

canRedo(): boolean

Defined in: index.ts:113

boolean


canUndo(): boolean

Defined in: index.ts:109

boolean


clearHistory(): void

Defined in: index.ts:122

Empty the undo and redo stacks. State is unchanged, so subscribers are not notified: a component showing canUndo() / canRedo() has to re-render itself after calling this.

void


dispatch(action): void

Defined in: index.ts:67

Dispatch an action to update state

ParameterType
actionAction

void

Store.dispatch


getState(): TState

Defined in: index.ts:63

Get the current state

TState

Store.getState


redo(): TState | undefined

Defined in: index.ts:105

TState | undefined


subscribe(listener): () => void

Defined in: index.ts:86

Subscribe to state changes Returns an unsubscribe function

ParameterType
listener(state) => void

() => void

Store.subscribe


undo(): TState | undefined

Defined in: index.ts:101

TState | undefined