aboutsummaryrefslogtreecommitdiffstats
path: root/node_modules/rxjs/src/internal/operators/publishLast.ts
diff options
context:
space:
mode:
authorPinapelz <yukais@pinapelz.com>2025-06-28 17:26:46 -0700
committerPinapelz <yukais@pinapelz.com>2025-06-28 17:43:56 -0700
commite4fa1e69e7ebfb627c7198fd1a9881e9327ec4d4 (patch)
tree06284a538a6008eca75051399e47db4e5d50301c /node_modules/rxjs/src/internal/operators/publishLast.ts
initial commit: scaffolding
Diffstat (limited to 'node_modules/rxjs/src/internal/operators/publishLast.ts')
-rw-r--r--node_modules/rxjs/src/internal/operators/publishLast.ts76
1 files changed, 76 insertions, 0 deletions
diff --git a/node_modules/rxjs/src/internal/operators/publishLast.ts b/node_modules/rxjs/src/internal/operators/publishLast.ts
new file mode 100644
index 0000000..ded47fb
--- /dev/null
+++ b/node_modules/rxjs/src/internal/operators/publishLast.ts
@@ -0,0 +1,76 @@
+import { Observable } from '../Observable';
+import { AsyncSubject } from '../AsyncSubject';
+import { ConnectableObservable } from '../observable/ConnectableObservable';
+import { UnaryFunction } from '../types';
+
+/**
+ * Returns a connectable observable sequence that shares a single subscription to the
+ * underlying sequence containing only the last notification.
+ *
+ * ![](publishLast.png)
+ *
+ * Similar to {@link publish}, but it waits until the source observable completes and stores
+ * the last emitted value.
+ * Similarly to {@link publishReplay} and {@link publishBehavior}, this keeps storing the last
+ * value even if it has no more subscribers. If subsequent subscriptions happen, they will
+ * immediately get that last stored value and complete.
+ *
+ * ## Example
+ *
+ * ```ts
+ * import { ConnectableObservable, interval, publishLast, tap, take } from 'rxjs';
+ *
+ * const connectable = <ConnectableObservable<number>>interval(1000)
+ * .pipe(
+ * tap(x => console.log('side effect', x)),
+ * take(3),
+ * publishLast()
+ * );
+ *
+ * connectable.subscribe({
+ * next: x => console.log('Sub. A', x),
+ * error: err => console.log('Sub. A Error', err),
+ * complete: () => console.log('Sub. A Complete')
+ * });
+ *
+ * connectable.subscribe({
+ * next: x => console.log('Sub. B', x),
+ * error: err => console.log('Sub. B Error', err),
+ * complete: () => console.log('Sub. B Complete')
+ * });
+ *
+ * connectable.connect();
+ *
+ * // Results:
+ * // 'side effect 0' - after one second
+ * // 'side effect 1' - after two seconds
+ * // 'side effect 2' - after three seconds
+ * // 'Sub. A 2' - immediately after 'side effect 2'
+ * // 'Sub. B 2'
+ * // 'Sub. A Complete'
+ * // 'Sub. B Complete'
+ * ```
+ *
+ * @see {@link ConnectableObservable}
+ * @see {@link publish}
+ * @see {@link publishReplay}
+ * @see {@link publishBehavior}
+ *
+ * @return A function that returns an Observable that emits elements of a
+ * sequence produced by multicasting the source sequence.
+ * @deprecated Will be removed in v8. To create a connectable observable with an
+ * {@link AsyncSubject} under the hood, use {@link connectable}.
+ * `source.pipe(publishLast())` is equivalent to
+ * `connectable(source, { connector: () => new AsyncSubject(), resetOnDisconnect: false })`.
+ * If you're using {@link refCount} after `publishLast`, use the {@link share} operator instead.
+ * `source.pipe(publishLast(), refCount())` is equivalent to
+ * `source.pipe(share({ connector: () => new AsyncSubject(), resetOnError: false, resetOnComplete: false, resetOnRefCountZero: false }))`.
+ * Details: https://rxjs.dev/deprecations/multicasting
+ */
+export function publishLast<T>(): UnaryFunction<Observable<T>, ConnectableObservable<T>> {
+ // Note that this has *never* supported a selector function like `publish` and `publishReplay`.
+ return (source) => {
+ const subject = new AsyncSubject<T>();
+ return new ConnectableObservable(source, () => subject);
+ };
+}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage