fetchToStateReceiver

fetchToStateReceiver method was created for fast state manage. You create method that return promise with new state. When event will be emited, method will be called and promise response replace required state.

import { fetchToStateReceiver } from 'eventrix';
import axios from 'axios';

const removeUser = (eventData, state, emit) => {
    return axios.delete(`http://somedomain.com/users/${eventData.id}`)
                .then(() => {
                    return state.users.filter(item => item.id !== eventData.id);
                });
}
const receiver = fetchToStateReceiver('users:remove', 'users', removeUser);

export default receiver;

Last updated