Search…
⌃K

@receiver

This decorator register class method as receiver in eventrix.
"useEventrix" decorator is required if You want use any of eventrix decorators.
Javascript
import React from 'react';
import { useEventrix, receiver } from 'eventrix';
@useEventrix
class ClientsService {
constructor(services) {
this.axios = services.axios;
}
@receiver(['Clients:loadList'])
getList(eventName, eventData, stateManager) {
return this.axios.get('http://someDomain.com', { params: eventData })
.then(({ data }) => {
stateManager.setState('clients', data);
});
};
}
export default ClientsService;
Below the same code without decorators
Javascript
import React from 'react';
import { EventsReceiver } from 'eventrix';
class ClientsService {
constructor(services) {
this.axios = services.axios;
this.eventrix = services.eventrix;
this.getListReceiver = new EventsReceiver(['Clients:loadList'], this.getList);
this.eventrix.useReceiver(this.getListReceiver);
}
getList = (eventName, eventData, stateManager) => {
return this.axios.get('http://someDomain.com', { params: eventData })
.then(({ data }) => {
stateManager.setState('clients', data);
});
};
}
export default ClientsService;