Skip to content

patchMethod<$Object, const MethodName>

Patches one method of an object for a scope, and returns a DisposableEx that restores it.

The scoped counterpart of MonkeyAroundComponent#registerMethodPatch, for a patch whose lifetime is a block rather than a component:

using _ = patchMethod({
$object: editor,
methodName: 'transaction',
patchHandler: ({ fallback }) => {
// ...
return fallback();
}
});

It takes the same parameters, and runs the same implementation, through a MonkeyAroundComponent of its own that is loaded here and unloaded on dispose. So once, patchToken and postPatchHandler behave exactly as they do there, and a patch stacked on the same method unloads in any order. Disposing more than once is a no-op.

Import:

import { patchMethod } from '@mnaoumov/obsidian-lib/components/monkey-around-component';

Signature:

function patchMethod(params: PatchMethodParams<$Object, MethodName>): DisposableEx

Parameters:

Parameter Type Description
params PatchMethodParams<$Object, MethodName> The parameters of the patch.

Returns: DisposableEx — A DisposableEx that removes the patch when disposed, for use with using.


Links to this page: