Skip to content

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:

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.

Import:

import { hasPatchToken } from 'obsidian-dev-utils/obsidian/components/monkey-around-component';

Signature:

function hasPatchToken($function: GenericFunction, patchToken: symbol): boolean

Parameters:

ParameterTypeDescription
$functionGenericFunction
patchTokensymbolThe patch token to check for.

Returns: boolean — Whether the function has the patch token.


Links to this page: