fetchToStateReceiver

Attribute name

Type

description

eventName

string

EventsReceiver event name

statePath

string

State name or path to state that will be replaced by fetch method response

fetchMethod

(eventData: any, state: any): Promise<any>

Fetch method. Method will be called when eventName emitted and must return Promise

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

Was this helpful?