Before adoption: this commit came in with the history the project adopted, so no landing records it.
Hooks are passed as options to the Immer class.
onAssign(state, prop, value)
Called for every property assigned to by a producer
onDelete(state, prop)
Called for every property deleted by a producer
onCopy(state)
Called whenever a copy becomes finalized
These hooks are passed an `ImmerState` object. (defined at the end of "src/index.d.ts")
The `state` is guaranteed to be both modified and finalized if ever passed to a hook.
if (onAssign && inDraft && !is(value, state.base[prop])) {
onAssign(state, prop, value)
}
}
each(root, finalizeProperty)
return root
}
}
modified:src/index.d.ts+14 added-1 removed
128 unmodified lines
129130export function isDraft(value: any): boolean131132export class Immer {133- constructor(config: {useProxies?: boolean; autoFreeze?: boolean})133+ constructor(config: {134+ useProxies?: boolean135+ autoFreeze?: boolean136+ onAssign?: (state: ImmerState, prop: keyof any, value: any) => void137+ onDelete?: (state: ImmerState, prop: keyof any) => void138+ onCopy?: (state: ImmerState) => void139+ })140 /**141 * The `produce` function takes a value and a "recipe function" (whose142 * return value often depends on the base state). The recipe function is143 * free to mutate its first argument however it wants. All mutations are
34 unmodified lines
178 * By default, feature detection is used, so calling this is rarely necessary.179 */180 setUseProxies(useProxies: boolean): void181}182+183+export interface ImmerState<T = any> {184+ parent?: ImmerState185+ base: T186+ copy: T187+ assigned: {[prop: string]: boolean}188+}