E.W.O. Next / All files / src/client/socket sender.ts

0% Statements 0/10
100% Branches 0/0
0% Functions 0/5
0% Lines 0/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28                                                       
/**
 * @module Client.Socket
 * Socket.IO Event Sender
 */
 
import { socket } from '@client/index';
 
/**
 * Events type:
 * * action => an action that will be queued.
 * * actionBatch => a list of actions. Each action will be executed only if the previous action is a success.
 * * update => an immediate action, with no queue.
 *
 * Returns:
 * each event return an object that indicate : the result (boolean), the accomplished steps (batch only),
 * and a message (if errors or string formating)
 */
 
const emit = (request, payload) => {
  socket.emit(request, payload, resp => {
    console.log(resp);
  });
};
 
export const action = (payload) => emit('action', payload);
export const actionBatch = (payload) => emit('actionBatch', payload);
export const update = (payload) => emit('update', payload);