
Security News
MCP Steering Committee Launches Official MCP Registry in Preview
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.
@citolab/preact-store
Advanced tools
Simple store to manage state using preact.
The Store class is a simple implementation of a Redux-like store. It provides a way to manage the state of an application, and to dispatch actions that modify the state.
To use the Store class, you first need to create an instance of it with an initial state:
const store = new Store(initialState);
You can then dispatch actions to modify the state:
store.dispatch({ type: 'INCREMENT' });
You can also subscribe to changes in the state:
store.subscribe(state => {
console.log('New state:', state);
});
constructor(initialState: T, restoreData?: { state: T; actions: Action<unknown>[]; })
Creates a new Store
instance with the given initial state. If restoreData is provided, it will restore the state and actions from the given data.
getState(): T
Returns the current state of the store.
getActions(): Action<unknown>[]
Returns an array of all the actions that have been dispatched to the store.
dispatch<P>(action: Action<P>): void
Dispatches an action to the store, which will modify the state.
reset(): void
Resets the store to its initial state and clears all actions.
restoreState(state: T, actions: Action<unknown>[]): void
Restores the state and actions of the store from the given data.
subscribe(listener: Listener<T>): void
Subscribes to changes in the state of the store. The listener function will be called whenever the state changes.
subscribeActions(listener: Listener<Action<unknown>>): void
Subscribes to new actions that are dispatched to the store. The listener function will be called whenever a new action is dispatched.
unsubscribe(listener: Listener<T>): void
Unsubscribes a listener from changes in the state of the store.
unsubscribeAll(): void
Unsubscribes all listeners from changes in the state of the store.
addReducer<P>(type: string, reducer: Reducer<T, P>): void
Adds a reducer function to the store. The reducer function will be called whenever an action with the given type is dispatched to the store.
useStore
A hook that can be used to subscribe to changes in the state of a store.
Action<P>
A type that represents an action that can be dispatched to the store. It has a type property that identifies the type of the action, and a payload property that contains the data for the action.
Listener<T>
A type that represents a listener function that can be subscribed to changes in the state of a store.
Reducer<T, P>
A type that represents a reducer function that can be added to a store. It takes the current state of the store and an action payload, and returns a new state.
IStore<T>
An interface that defines the methods and properties of a store. It extends the IStore interface, which is a more generic interface that defines the methods and properties of any store.
FAQs
simple preact store
The npm package @citolab/preact-store receives a total of 67 weekly downloads. As such, @citolab/preact-store popularity was classified as not popular.
We found that @citolab/preact-store demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.
Product
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
Research
/Security News
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.