1.1.2 • Published 4 years ago

channel-store v1.1.2

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

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

4 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago