MCPcopy
hub / github.com/mobxjs/mobx / patch

Function patch

packages/mobx-react/src/utils/utils.ts:125–148  ·  view source on GitHub ↗
(target: object, methodName: string, mixinMethod: Function)

Source from the content-addressed store, hash-verified

123}
124
125export function patch(target: object, methodName: string, mixinMethod: Function): void {
126 const mixins = getMixins(target, methodName)
127
128 if (mixins.methods.indexOf(mixinMethod) < 0) {
129 mixins.methods.push(mixinMethod)
130 }
131
132 const oldDefinition = Object.getOwnPropertyDescriptor(target, methodName)
133 if (oldDefinition && oldDefinition[mobxPatchedDefinition]) {
134 // already patched definition, do not repatch
135 return
136 }
137
138 const originalMethod = target[methodName]
139 const newDefinition = createDefinition(
140 target,
141 methodName,
142 oldDefinition ? oldDefinition.enumerable : undefined,
143 mixins,
144 originalMethod
145 )
146
147 Object.defineProperty(target, methodName, newDefinition)
148}
149
150function createDefinition(
151 target: object,

Callers 2

disposeOnUnmountFunction · 0.90

Calls 2

getMixinsFunction · 0.85
createDefinitionFunction · 0.85

Tested by

no test coverage detected