Skip to content

obsidian/components/monkey-around-component

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

ClassDescription
MonkeyAroundComponentA component that manages monkey-patches with lifecycle-bound cleanup. All patches registered via this component are automatically uninstalled when the component unloads.
InterfaceDescription
MonkeyAroundComponentRegisterFunctionPatchParamsParameters passed to MonkeyAroundComponent#registerFunctionPatch.
MonkeyAroundComponentRegisterMethodPatchParamsParameters passed to MonkeyAroundComponent#registerMethodPatch.
PatchHandlerParamsParameters passed to a PatchHandlerFn callback.
PostPatchHandlerParamsParameters passed to a PostPatchHandlerFn callback.
FunctionDescription
aroundApplies a patch to the object. Better strongly-typed version of monkey-around.
hasPatchTokenChecks if a function has a specific patch token.
TypeDescription
FactoriesA type of the factories to apply to the object.
FunctionKeysKeys 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.
MethodKeysKeys 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).
PatchHandlerFnA patch handler function that intercepts calls to a method on an object.
PostPatchHandlerFnA post-patch handler function that runs after a patch is applied.