function wireUpEventHandler()

in packages/search-ui/src/Events.ts [19:40]


function wireUpEventHandler(
  handlerName: string,
  apiConnector: APIConnector,
  handlerParam
) {
  if (handlerParam) {
    // Passes a 'next' parameter which allows a handler to work as
    // middleware for a connector
    if (apiConnector) {
      const next = apiConnector[handlerName].bind(apiConnector);
      return (...params) => {
        return handlerParam(...params, next);
      };
    }
    return handlerParam;
  }
  if (apiConnector && apiConnector[handlerName])
    return apiConnector[handlerName].bind(apiConnector);
  return () => {
    throw `No ${handlerName} handler provided and no Connector provided. You must configure one or the other.`;
  };
}