# All files / src/utils handleEvents.js

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

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    2414x
    2x
    3x
    1x

    1x
    1x

    4x
    3x
    3x
    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');
          }

          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
            }
          }
        }
      };
    };