| 148 | } |
| 149 | |
| 150 | function 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 | } |