feat(lib/patcher/types): export UnpatchFunction
This commit is contained in:
parent
37a20160db
commit
709a944d49
4 changed files with 21 additions and 8 deletions
|
|
@ -4,7 +4,12 @@ import {
|
|||
unproxy,
|
||||
} from '../_internal'
|
||||
import type { HookNode, PatchedFunctionProxyState } from '../_internal'
|
||||
import type { AfterHook, FiniteDomain, UnknownFunction } from '../types'
|
||||
import type {
|
||||
AfterHook,
|
||||
FiniteDomain,
|
||||
UnknownFunction,
|
||||
UnpatchFunction,
|
||||
} from '../types'
|
||||
|
||||
function unpatchAfter<T extends UnknownFunction>(
|
||||
state: PatchedFunctionProxyState<PropertyKey, T>,
|
||||
|
|
@ -63,12 +68,12 @@ function unpatchAfter<T extends UnknownFunction>(
|
|||
export function after<
|
||||
Parent extends Record<Key, UnknownFunction>,
|
||||
Key extends keyof Parent,
|
||||
>(parent: Parent, key: Key, hook: AfterHook<Parent[Key]>): () => void
|
||||
>(parent: Parent, key: Key, hook: AfterHook<Parent[Key]>): UnpatchFunction
|
||||
export function after<Key extends PropertyKey, Value extends UnknownFunction>(
|
||||
parent: Record<Key, Value>,
|
||||
key: FiniteDomain<Key>,
|
||||
hook: AfterHook<Value>,
|
||||
) {
|
||||
): UnpatchFunction {
|
||||
const target = parent[key]
|
||||
|
||||
let state = patchedFunctionProxyStates.get(target)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,12 @@ import {
|
|||
unproxy,
|
||||
} from '../_internal'
|
||||
import type { HookNode, PatchedFunctionProxyState } from '../_internal'
|
||||
import type { BeforeHook, FiniteDomain, UnknownFunction } from '../types'
|
||||
import type {
|
||||
BeforeHook,
|
||||
FiniteDomain,
|
||||
UnknownFunction,
|
||||
UnpatchFunction,
|
||||
} from '../types'
|
||||
|
||||
function unpatchBefore<T extends UnknownFunction>(
|
||||
state: PatchedFunctionProxyState<PropertyKey, T>,
|
||||
|
|
@ -63,12 +68,12 @@ function unpatchBefore<T extends UnknownFunction>(
|
|||
export function before<
|
||||
Parent extends Record<Key, UnknownFunction>,
|
||||
Key extends keyof Parent,
|
||||
>(parent: Parent, key: Key, hook: BeforeHook<Parent[Key]>): () => void
|
||||
>(parent: Parent, key: Key, hook: BeforeHook<Parent[Key]>): UnpatchFunction
|
||||
export function before<Key extends PropertyKey, Value extends UnknownFunction>(
|
||||
parent: Record<Key, Value>,
|
||||
key: FiniteDomain<Key>,
|
||||
hook: BeforeHook<Value>,
|
||||
) {
|
||||
): UnpatchFunction {
|
||||
const target = parent[key]
|
||||
|
||||
let state = patchedFunctionProxyStates.get(target)
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import type {
|
|||
FiniteDomain,
|
||||
InsteadHook,
|
||||
UnknownFunction,
|
||||
UnpatchFunction,
|
||||
} from '../types'
|
||||
|
||||
const insteadHookProxyHandler = {
|
||||
|
|
@ -110,12 +111,12 @@ function unpatchInstead<T extends UnknownFunction>(
|
|||
export function instead<
|
||||
Parent extends Record<Key, UnknownFunction>,
|
||||
Key extends keyof Parent,
|
||||
>(parent: Parent, key: Key, hook: InsteadHook<Parent[Key]>): () => void
|
||||
>(parent: Parent, key: Key, hook: InsteadHook<Parent[Key]>): UnpatchFunction
|
||||
export function instead<Key extends PropertyKey, Value extends UnknownFunction>(
|
||||
parent: Record<Key, Value>,
|
||||
key: FiniteDomain<Key>,
|
||||
hook: InsteadHook<Value>,
|
||||
) {
|
||||
): UnpatchFunction {
|
||||
const target = parent[key]
|
||||
|
||||
let state = patchedFunctionProxyStates.get(target)
|
||||
|
|
|
|||
|
|
@ -222,3 +222,5 @@ export type OverloadUnionNewableInner<
|
|||
ConcreteNewable<Args, Return>
|
||||
>
|
||||
: never
|
||||
|
||||
export type UnpatchFunction = () => void
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue