(klass: any, observable: Observable<any>, zone: NgZone, options: {
spy?: {
get?: ((name: string, it: any) => void),
apply?: ((name: string, args: any[], it: any) => void)
}
} = {})
| 30 | // INVESTIGATE should we make the Proxy revokable and do some cleanup? |
| 31 | // right now it's fairly simple but I'm sure this will grow in complexity |
| 32 | export const ɵlazySDKProxy = (klass: any, observable: Observable<any>, zone: NgZone, options: { |
| 33 | spy?: { |
| 34 | get?: ((name: string, it: any) => void), |
| 35 | apply?: ((name: string, args: any[], it: any) => void) |
| 36 | } |
| 37 | } = {}) => { |
| 38 | return new Proxy(klass, { |
| 39 | get: (_, name: string) => zone.runOutsideAngular(() => { |
| 40 | if (klass[name]) { |
| 41 | if (options?.spy?.get) { |
| 42 | options.spy.get(name, klass[name]); |
| 43 | } |
| 44 | return klass[name]; |
| 45 | } |
| 46 | if (noopFunctions.indexOf(name) > -1) { |
| 47 | return () => undefined; |
| 48 | } |
| 49 | const promise = observable.toPromise().then(mod => { |
| 50 | const ret = mod?.[name]; |
| 51 | // TODO move to proper type guards |
| 52 | if (typeof ret === 'function') { |
| 53 | return ret.bind(mod); |
| 54 | } else if (ret?.then) { |
| 55 | return ret.then((res: any) => zone.run(() => res)); |
| 56 | } else { |
| 57 | return zone.run(() => ret); |
| 58 | } |
| 59 | }); |
| 60 | // recurse the proxy |
| 61 | return new Proxy(() => undefined, { |
| 62 | get: (_, name) => promise[name], |
| 63 | // TODO handle callbacks as transparently as I can |
| 64 | apply: (self, _, args) => promise.then(it => { |
| 65 | const res = it?.(...args); |
| 66 | if (options?.spy?.apply) { |
| 67 | options.spy.apply(name, args, res); |
| 68 | } |
| 69 | return res; |
| 70 | }) |
| 71 | } |
| 72 | ); |
| 73 | }) |
| 74 | }); |
| 75 | }; |
| 76 | |
| 77 | export const ɵapplyMixins = (derivedCtor: any, constructors: any[]) => { |
| 78 | constructors.forEach((baseCtor) => { |
no test coverage detected