1.1.3 • Published 4 years ago
type-regi v1.1.3
type-regi
simple event store for react/typescript.
type SampleState = {
count: number;
};
type SampleActions = {
increment: {
value: number;
};
};
const defaultState: SampleState = {
count: 0
};
const actions = {
increment(state: SampleState, payload: { value: number }) {
const { value } = payload;
return {
count: state.count + value
};
}
};
const store = new TypeRegi<SampleState, SampleActions>(defaultState, actions);
store.subscribe((state: SampleState) => {
console.log('count is ${state.count}.');
});
store.dispatch('increment', { value: 1 });
// => "count is 1"