Eventrix

Example of simple use of Eventrix

import { Eventrix, EventsReceiver } from 'eventrix';

const usersEventsReceiver = new EventsReceiver(
    'createUserEventName',
    (eventName, eventData, stateManager) => {
        const user = eventData.user;
        const users = stateManager.getState('usersList');
        stateManager.setState('usersList', [user, ...users]);
    }
);

const initialState = {
    usersList: [],
}

const eventsReceivers = [
    usersEventsReceiver,
];

const eventrix = new Eventrix(initialState, eventsReceivers);

export default eventrix;

When You emit event with name "createUserEventName" usersEventsReceiver will be invoked and change state of "usersList".

const user = {
    id: 1,
    name: 'Max',
    age: 30,
}

eventrix.emit('createUserEventName', { user });

Last updated