type-regi

event emitter with typescript typing.

Usage no npm install needed!

<script type="module">
  import typeRegi from 'https://cdn.skypack.dev/type-regi';
</script>

README

type-regi

simple event store for react/typescript.

CircleCI

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"