Skip to content

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

License

Notifications You must be signed in to change notification settings

zpxp/channel-store

Repository files navigation

channel-store

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;
});

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published