|
|
@@ -0,0 +1,35 @@
|
|
|
+import {ElementRef} from '@angular/core';
|
|
|
+import {TransmitterInterface} from './interface/transmitter.interface';
|
|
|
+import {CommonStackManager} from '@ex-helpers/stack';
|
|
|
+import {TransmitterableInterface} from './interface/transmitterable.interface';
|
|
|
+import {Observable} from 'rxjs';
|
|
|
+
|
|
|
+export class Transmitter extends CommonStackManager<TransmitterableInterface, string> implements TransmitterInterface {
|
|
|
+ public static get(ref: ElementRef): TransmitterInterface {
|
|
|
+ if (!ref.transmitter) {
|
|
|
+ ref.transmitter = new Transmitter(ref);
|
|
|
+ }
|
|
|
+ return ref.transmitter;
|
|
|
+ }
|
|
|
+
|
|
|
+ constructor(public ref: ElementRef) {
|
|
|
+ super('name');
|
|
|
+ }
|
|
|
+
|
|
|
+ public waitFor<T>(name: string): Observable<TransmitterableInterface<T>> {
|
|
|
+ return new Observable(observer => {
|
|
|
+ const s = this.subscribe(() => {
|
|
|
+ const item = this.get(name);
|
|
|
+ if (item) {
|
|
|
+ observer.next(item);
|
|
|
+ observer.complete();
|
|
|
+ if (s) {
|
|
|
+ s.unsubscribe();
|
|
|
+ } else {
|
|
|
+ setTimeout(() => s.unsubscribe());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|