| 112 | } |
| 113 | |
| 114 | class EventEmitter_ extends Subject<any> implements OutputRef<any> { |
| 115 | // tslint:disable-next-line:require-internal-with-underscore |
| 116 | __isAsync: boolean; |
| 117 | destroyRef: DestroyRef | undefined = undefined; |
| 118 | private readonly pendingTasks: PendingTasksInternal | undefined = undefined; |
| 119 | |
| 120 | constructor(isAsync: boolean = false) { |
| 121 | super(); |
| 122 | this.__isAsync = isAsync; |
| 123 | |
| 124 | // Attempt to retrieve a `DestroyRef` and `PendingTasks` optionally. |
| 125 | // For backwards compatibility reasons, this cannot be required. |
| 126 | if (isInInjectionContext()) { |
| 127 | // `DestroyRef` is optional because it is not available in all contexts. |
| 128 | // But it is useful to properly complete the `EventEmitter` if used with `outputToObservable` |
| 129 | // when the component/directive is destroyed. (See `outputToObservable` for more details.) |
| 130 | this.destroyRef = inject(DestroyRef, {optional: true}) ?? undefined; |
| 131 | this.pendingTasks = inject(PendingTasksInternal, {optional: true}) ?? undefined; |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | emit(value?: any) { |
| 136 | const prevConsumer = setActiveConsumer(null); |
| 137 | try { |
| 138 | super.next(value); |
| 139 | } finally { |
| 140 | setActiveConsumer(prevConsumer); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | override subscribe(observerOrNext?: any, error?: any, complete?: any): Subscription { |
| 145 | let nextFn = observerOrNext; |
| 146 | let errorFn = error || (() => null); |
| 147 | let completeFn = complete; |
| 148 | |
| 149 | if (observerOrNext && typeof observerOrNext === 'object') { |
| 150 | const observer = observerOrNext as PartialObserver<unknown>; |
| 151 | nextFn = observer.next?.bind(observer); |
| 152 | errorFn = observer.error?.bind(observer); |
| 153 | completeFn = observer.complete?.bind(observer); |
| 154 | } |
| 155 | |
| 156 | if (this.__isAsync) { |
| 157 | errorFn = this.wrapInTimeout(errorFn); |
| 158 | |
| 159 | if (nextFn) { |
| 160 | nextFn = this.wrapInTimeout(nextFn); |
| 161 | } |
| 162 | |
| 163 | if (completeFn) { |
| 164 | completeFn = this.wrapInTimeout(completeFn); |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | const sink = super.subscribe({next: nextFn, error: errorFn, complete: completeFn}); |
| 169 | |
| 170 | if (observerOrNext instanceof Subscription) { |
| 171 | observerOrNext.add(sink); |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…