A class that can be used to represent the entire application store. To create an instance of the store, you can use the constructor of the class.
const store = new Store(initialState: TState, options?: StoreOptions<TState, TUpdater>)
const store = new Store(initialState: TState, options?: StoreOptions<TState, TUpdater>)
subscribe: Subscribes a listener to the store. The method returns a function to unsubscribe the listener.
subscribe = (listener: Listener)
subscribe = (listener: Listener)
setState: Updates the store's state using the provided updater function.
setState = (
updater: TUpdater,
opts?:{
priority: Priority
})
setState = (
updater: TUpdater,
opts?:{
priority: Priority
})
batch: Allows you to call setState multiple times in the callback while only notifying listeners of changes once per batched execution.
batch = (cb: () => void)
batch = (cb: () => void)
An interface representing the properties available to configure in Store.
updateFn?: A function to updates the current store's state.
updateFn?: (previous: TState) => (updater: TUpdater) => TState;
updateFn?: (previous: TState) => (updater: TUpdater) => TState;
onSubscribe?: A callback function called when a listener is subscribed to the store. Returns a function to unsubscribe the listener.
onSubscribe?: (
listener: Listener,
store: Store<TState, TUpdater>,
) => () => void;
onSubscribe?: (
listener: Listener,
store: Store<TState, TUpdater>,
) => () => void;
onUpdate?: A callback function called when the store's state is updated.
onUpdate?: (opts: { priority: Priority }) => void;
onUpdate?: (opts: { priority: Priority }) => void;
defaultPriority?: The default priority to use when no priority is specified.
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.