(target: object, methodName: string, mixinMethod: Function)
| 123 | } |
| 124 | |
| 125 | export 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 | |
| 150 | function createDefinition( |
| 151 | target: object, |
no test coverage detected