@espressif/rainmaker-base-cdf
    Preparing search index...

    Function proxyActionHandler

    • Intercepts and wraps nested functions within an object with custom logic.

      Parameters

      • target: object

        The object containing the nested functions to be intercepted.

      • path: string

        The path to the nested function to be intercepted.

      • interceptor: Interceptor

        The interceptor function to wrap the original function.

      Returns void

      const target = {
      a: {
      b: {
      c: async function() {
      console.log("Original function");
      }
      }
      }
      };
      const interceptor = async (originalFunction, context, args) => {
      console.log("Interceptor function");
      return await originalFunction.call(context, ...args);
      };
      proxyActionHandler(target, "a.b.c", interceptor);
      target.a.b.c(); // Output: "Interceptor function" followed by "Original function"

      This function is useful for intercepting and wrapping nested functions within an object with custom logic. It allows you to modify the behavior of the original function without changing its implementation. The interceptor function receives the original function, context, and arguments as parameters, and can perform custom actions before and after calling the original function. The original function is called using the call method to ensure that the context is preserved. The path parameter specifies the nested function to be intercepted, using dot notation to traverse nested objects. If the path is invalid or the property is not a function, an error will be thrown. The interceptor function should return the result of the original function call, allowing you to modify the return value if needed.

      • createInterceptor
      • Interceptor
      • Action
      • Rollback