I have inherited an angular project where java style entity instances are mimicked using plain javascript objects.
This is how fake injection is implemented:
export class MyEntity {
private http: Http;
private someObservable: Observable<any>;
init(dependencies, ...) {
this.http = dependencies.http;
this.someObservable = dependencies.someObservable;
this.someObservable.subscribe((res) => { ...unimportant logic... });
}
}
then in DI enabled code:
entity = new MyEntity();
entity.init({ http: this.http, someObservable: this.someObservable, ... }, ...);
My questions:
Can http "malfunction" like this? I'm worried that it might not work fully (CD, interceptors or events might not trigger. etc). Right now it does not show any issues, but might be the code just wasn't tested well enough.
Is there any way to release subscriptions created here conveniently? Normally i'd take care of that in an onDestroy hook, but that isn't available for plain classes. Some of the observables here are continuous, won't complete after first emit.
Refactor would take quite some time, so if there is a safe solution that might be preferable even if it's relatively ugly.