qkreltms / react-action-listener

Middleware, React hook which allows making side effect and listening actions of Context or Redux
MIT License
8 stars 0 forks source link

feat: Implement binary search when finding registered actions #45

Closed qkreltms closed 3 years ago

qkreltms commented 3 years ago

Is your feature request related to a problem? Please describe. It seems we can reduce time when implementing binary search when finding registered actions.

  const middleware: any =
          .filter(({ type }) => {
            if (config.isDebugContext) {
              const time = formatTime(new Date());
              console.group();
              console.log(`${action.type} %c@`, timeStyles, time);
              console.log(
                '%c action    ',
                actionTitleStyles,
                JSON.stringify(action)
              );
              console.groupEnd();
            }
            if (type === action.type) {
              return true;
            }
            // then check if listener type is array and has action.type
            if (type.constructor === Array && type.indexOf(action.type) > -1) {
              return true;
            }
            return false;
          })
          .map((listener) => listener.listener(action));
      }