package.esm2022.src.event_emitter.mjs Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
Angular - the core framework
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { setActiveConsumer } from '@angular/core/primitives/signals';
import { Subject, Subscription } from 'rxjs';
import { isInInjectionContext } from './di/contextual';
import { inject } from './di/injector_compatibility';
import { DestroyRef } from './linker/destroy_ref';
import { PendingTasks } from './pending_tasks';
class EventEmitter_ extends Subject {
constructor(isAsync = false) {
super();
this.destroyRef = undefined;
this.pendingTasks = undefined;
this.__isAsync = isAsync;
// Attempt to retrieve a `DestroyRef` and `PendingTasks` optionally.
// For backwards compatibility reasons, this cannot be required.
if (isInInjectionContext()) {
this.destroyRef = inject(DestroyRef, { optional: true }) ?? undefined;
this.pendingTasks = inject(PendingTasks, { optional: true }) ?? undefined;
}
}
emit(value) {
const prevConsumer = setActiveConsumer(null);
try {
super.next(value);
}
finally {
setActiveConsumer(prevConsumer);
}
}
subscribe(observerOrNext, error, complete) {
let nextFn = observerOrNext;
let errorFn = error || (() => null);
let completeFn = complete;
if (observerOrNext && typeof observerOrNext === 'object') {
const observer = observerOrNext;
nextFn = observer.next?.bind(observer);
errorFn = observer.error?.bind(observer);
completeFn = observer.complete?.bind(observer);
}
if (this.__isAsync) {
errorFn = this.wrapInTimeout(errorFn);
if (nextFn) {
nextFn = this.wrapInTimeout(nextFn);
}
if (completeFn) {
completeFn = this.wrapInTimeout(completeFn);
}
}
const sink = super.subscribe({ next: nextFn, error: errorFn, complete: completeFn });
if (observerOrNext instanceof Subscription) {
observerOrNext.add(sink);
}
return sink;
}
wrapInTimeout(fn) {
return (value) => {
const taskId = this.pendingTasks?.add();
setTimeout(() => {
fn(value);
if (taskId !== undefined) {
this.pendingTasks?.remove(taskId);
}
});
};
}
}
/**
* @publicApi
*/
export const EventEmitter = EventEmitter_;
//#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IpO1xuICAgIH1cblxuICAgIGlmICh0aGlzLl9faXNBc3luYykge1xuICAgICAgZXJyb3JGbiA9IHRoaXMud3JhcEluVGltZW91dChlcnJvckZuKTtcblxuICAgICAgaWYgKG5leHRGbikge1xuICAgICAgICBuZXh0Rm4gPSB0aGlzLndyYXBJblRpbWVvdXQobmV4dEZuKTtcbiAgICAgIH1cblxuICAgICAgaWYgKGNvbXBsZXRlRm4pIHtcbiAgICAgICAgY29tcGxldGVGbiA9IHRoaXMud3JhcEluVGltZW91dChjb21wbGV0ZUZuKTtcbiAgICAgIH1cbiAgICB9XG5cbiAgICBjb25zdCBzaW5rID0gc3VwZXIuc3Vic2NyaWJlKHtuZXh0OiBuZXh0Rm4sIGVycm9yOiBlcnJvckZuLCBjb21wbGV0ZTogY29tcGxldGVGbn0pO1xuXG4gICAgaWYgKG9ic2VydmVyT3JOZXh0IGluc3RhbmNlb2YgU3Vic2NyaXB0aW9uKSB7XG4gICAgICBvYnNlcnZlck9yTmV4dC5hZGQoc2luayk7XG4gICAgfVxuXG4gICAgcmV0dXJuIHNpbms7XG4gIH1cblxuICBwcml2YXRlIHdyYXBJblRpbWVvdXQoZm46ICh2YWx1ZTogdW5rbm93bikgPT4gYW55KSB7XG4gICAgcmV0dXJuICh2YWx1ZTogdW5rbm93bikgPT4ge1xuICAgICAgY29uc3QgdGFza0lkID0gdGhpcy5wZW5kaW5nVGFza3M/LmFkZCgpO1xuICAgICAgc2V0VGltZW91dCgoKSA9PiB7XG4gICAgICAgIGZuKHZhbHVlKTtcbiAgICAgICAgaWYgKHRhc2tJZCAhPT0gdW5kZWZpbmVkKSB7XG4gICAgICAgICAgdGhpcy5wZW5kaW5nVGFza3M/LnJlbW92ZSh0YXNrSWQpO1xuICAgICAgICB9XG4gICAgICB9KTtcbiAgICB9O1xuICB9XG59XG5cbi8qKlxuICogQHB1YmxpY0FwaVxuICovXG5leHBvcnQgY29uc3QgRXZlbnRFbWl0dGVyOiB7XG4gIG5ldyAoaXNBc3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