Skip to content

components/monkey-around-component

Improved type-safe wrapper of https://www.npmjs.com/package/monkey-around library.

Class Description
MonkeyAroundComponent A component that manages monkey-patches with lifecycle-bound cleanup. All patches registered via this component are automatically uninstalled when the component unloads.
Interface Description
MonkeyAroundComponentRegisterFunctionPatchParams Parameters passed to MonkeyAroundComponent#registerFunctionPatch.
MonkeyAroundComponentRegisterMethodPatchParams Parameters passed to MonkeyAroundComponent#registerMethodPatch.
PatchHandlerParams Parameters passed to a PatchHandlerFunction callback.
PostPatchHandlerParams Parameters passed to a PostPatchHandlerFunction callback.
Function Description
around Applies a patch to the object. Better strongly-typed version of monkey-around.
hasPatchToken Checks if a function has a specific patch token. A token is carried by the method a MonkeyAroundComponent#registerMethodPatch call INSTALLED, so the intended caller is a later patch of the same method, checking the originalMethod it wrapped in order to defer to the patch already in place: ts patchHandler: (\{ fallback, originalMethod \}) => \{ if (hasPatchToken(originalMethod, PATCH_TOKEN)) \{ return fallback(); \} ... \} The check is made per call, so it stops reporting the earlier patch once that patch’s component unloads.
Type Description
Factories A type of the factories to apply to the object.
FunctionKeys Keys of Obj whose value is callable — a method, or a function-like object such as a Debouncer. These are the members accepted by MonkeyAroundComponent#registerFunctionPatch.
MethodKeys Keys of Obj whose value is a plain function (a “real method”). Function-like objects that carry extra members are excluded — e.g. a Debouncer (which adds cancel/run) belongs to MonkeyAroundComponent#registerFunctionPatch, not MonkeyAroundComponent#registerMethodPatch. The check is whether the member has any own keys beyond a bare function’s (Exclude<keyof T, keyof GenericFunction> is never).
PatchHandlerFunction A patch handler function that intercepts calls to a method on an object.
PostPatchHandlerFunction A post-patch handler function that runs after a patch is applied. It returns nothing and is not handed the patched method: the method installed is always the one the patch builds, so a post-patch handler cannot graft members onto it. A capability beyond the patched method’s own signature belongs on the plugin’s published API instead.