import { assertTweakedObject } from "../tweaker/core" import { lazy } from "../utils" import type { AnyFunction } from "../utils/AnyFunction" import { BuiltInAction } from "./builtInActions" import { ActionContextActionType } from "./context" import { wrapInAction } from "./wrapInAction" /** * Calls an object method wrapped in an action. * * @param node Target object. * @param methodName Method name. */ export function applyMethodCall( node: O, methodName: K, ...args: FN extends AnyFunction ? Parameters : never ): FN extends AnyFunction ? ReturnType : never { assertTweakedObject(node, "node") return wrappedInternalApplyMethodCall().call(node, methodName as string | number, args) } /** * @internal */ export function internalApplyMethodCall(this: any, methodName: string | number, args: any[]): any { return this[methodName](...args) } const wrappedInternalApplyMethodCall = lazy(() => wrapInAction({ nameOrNameFn: BuiltInAction.ApplyMethodCall, fn: internalApplyMethodCall, actionType: ActionContextActionType.Sync, }) )