channel-store
TypeScript icon, indicating that this package has built-in type declarations

1.1.2 • Public • Published

channel-store

Bundlephobia gzip + minified

A channel-event middleware to create an ambient state that functions similar to redux but without the large amount of boilerplate and verbosity.

Bundlephobia gzip + minified

Installation

yarn add channel-store

npm install channel-store

Use

import { createHub } from "channel-event";
import { createStoreMiddleware, IStoreEvents } from "channel-store";
 
export interface AppStore {
   count: number
}
 
 
const hub = createHub(...);
 
const store = createStoreMiddleware<AppStore>(hub)
                  .addDefaultState({ count: 4 })
                  .build();
 
 
const channel = hub.newChannel<IStoreEvents>();
 
channel.send(storeEvents.UPDATE_STATE, state => ({ count: state.count + 1 }))
 
 

To read the store

 
const state = store.getState();
 
// or
const state = channel.send(storeEvents.GET_STATE);
 
 
// listen to state change
channel.listen(storeEvents.STATE_UPDATED, data => {
   const newState = data.payload;
});
 

Package Sidebar

Install

npm i channel-store

Weekly Downloads

13

Version

1.1.2

License

MIT

Unpacked Size

23.7 kB

Total Files

13

Last publish

Collaborators

  • zpxp