Skip to content

Commit 131231b

Browse files
author
Duke
committed
fix: pushObservable should emit initial value
1 parent 2d2d925 commit 131231b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/rx.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,14 @@ const noops: Unsubscribe = () => { }
109109
* @returns {PushObservable<T>} The created push-based observable.
110110
*/
111111
export function pushObservable<T>(initialValue?: T): PushObservable<T> {
112-
let subject: Subject<T> = {
112+
let subject: Subject<T> = initialValue === undefined ? {
113113
kind: 'init',
114114
subscribers: new Set()
115-
};
115+
} : {
116+
kind: 'active',
117+
subscribers: new Set(),
118+
lastValue: initialValue
119+
}
116120

117121
function handleNext(value: T) {
118122
if (subject.kind === 'error' || subject.kind === 'complete') return;
@@ -184,10 +188,6 @@ export function pushObservable<T>(initialValue?: T): PushObservable<T> {
184188
complete: obs.complete ?? noops
185189
});
186190

187-
if (initialValue !== undefined) {
188-
obs.next?.(initialValue);
189-
}
190-
191191
break;
192192
}
193193

0 commit comments

Comments
 (0)