Search…
⌃K

@fetchToState

This decorator register class method as fetchToStateReceiver in eventrix.
useEventrix" decorator is required if You want use any of eventrix decorators.
Javascript
import React from 'react';
import { useEventrix, fetchToState } from 'eventrix';
@useEventrix
class ClientsService {
constructor(services) {
this.axios = services.axios;
}
@fetchToState('Clients:loadList', 'clients')
getList(params, state, emit) {
return this.axios.get('http://someDomain.com', { params })
.then(({ data }) => {
return data;
});
};
}
export default ClientsService;
Below example of code without decorators
Javascript
import React from 'react';
import { fetchToStateReceiver } from 'eventrix';
class ClientsService {
constructor(services) {
this.axios = services.axios;
this.eventrix = services.eventrix;
this.getListReceiver = fetchToStateReceiver('Clients:loadList', 'clients', this.getList);
this.eventrix.useReceiver(this.getListReceiver);
}
getList = (params, state, emit) => {
return this.axios.get('http://someDomain.com', { params })
.then(({ data }) => {
return data;
});
};
}
export default ClientsService;