# All files / src/utils handleEvents.js

100% Statements 10/10
100% Branches 8/8
100% Functions 3/3
100% Lines 10/10

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
    2419x
    12x
    48x
    1x

    11x
    13x

    20x
    10x
    10x
    1x

     module.exports = handlers => {
      Object.keys(handlers).forEach(key => {
        if (key[0].toUpperCase() !== key[0]) {
          throw new Error('Event name should start with a capital letter');
        }
      });

      return async events => {
        for (const event of events) {
          // istanbul ignore next
          if (event.event === undefined) {
            console.warn('Unknown event. ABI can be outdated'); // eslint-disable-line no-console
          }

          if (handlers[event.event]) {
            const result = handlers[event.event](event);
            if (result && typeof result.then === 'function') {
              await result; // eslint-disable-line no-await-in-loop
            }
          }
        }
      };
    };