(inst: T, group: string, methods: _LazyMethodsOf<T>)
| 32 | }>; |
| 33 | |
| 34 | function _installLazyMethods<T extends object>(inst: T, group: string, methods: _LazyMethodsOf<T>): void { |
| 35 | const proto = Object.getPrototypeOf(inst); |
| 36 | let installed = _installedGroups.get(proto); |
| 37 | if (!installed) { |
| 38 | installed = new Set(); |
| 39 | _installedGroups.set(proto, installed); |
| 40 | } |
| 41 | if (installed.has(group)) return; |
| 42 | installed.add(group); |
| 43 | for (const key in methods) { |
| 44 | const fn = methods[key]!; |
| 45 | Object.defineProperty(proto, key, { |
| 46 | configurable: true, |
| 47 | enumerable: false, |
| 48 | get(this: any) { |
| 49 | const bound = fn.bind(this); |
| 50 | Object.defineProperty(this, key, { |
| 51 | configurable: true, |
| 52 | writable: true, |
| 53 | enumerable: true, |
| 54 | value: bound, |
| 55 | }); |
| 56 | return bound; |
| 57 | }, |
| 58 | set(this: any, v: unknown) { |
| 59 | Object.defineProperty(this, key, { |
| 60 | configurable: true, |
| 61 | writable: true, |
| 62 | enumerable: true, |
| 63 | value: v, |
| 64 | }); |
| 65 | }, |
| 66 | }); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | /////////////////////////////////////////// |
| 71 | /////////////////////////////////////////// |
no test coverage detected