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

Function createDefinition

packages/mobx-react/src/utils/utils.ts:150–180  ·  view source on GitHub ↗
(
    target: object,
    methodName: string,
    enumerable: any,
    mixins: Mixins,
    originalMethod: Function
)

Source from the content-addressed store, hash-verified

148}
149
150function createDefinition(
151 target: object,
152 methodName: string,
153 enumerable: any,
154 mixins: Mixins,
155 originalMethod: Function
156): PropertyDescriptor {
157 let wrappedFunc = wrapFunction(originalMethod, mixins)
158
159 return {
160 // @ts-ignore
161 [mobxPatchedDefinition]: true,
162 get: function () {
163 return wrappedFunc
164 },
165 set: function (value) {
166 if (this === target) {
167 wrappedFunc = wrapFunction(value, mixins)
168 } else {
169 // when it is an instance of the prototype/a child prototype patch that particular case again separately
170 // since we need to store separate values depending on wether it is the actual instance, the prototype, etc
171 // e.g. the method for super might not be the same as the method for the prototype which might be not the same
172 // as the method for the instance
173 const newDefinition = createDefinition(this, methodName, enumerable, mixins, value)
174 Object.defineProperty(this, methodName, newDefinition)
175 }
176 },
177 configurable: true,
178 enumerable: enumerable
179 }
180}

Callers 1

patchFunction · 0.85

Calls 1

wrapFunctionFunction · 0.85

Tested by

no test coverage detected