-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Description
Describe the bug
The following code shows a weird behavior of .pipe():
const RxJs = require('rxjs');
const mySubj$ = new RxJs.Subject();
const doubled$ = mySubj$.pipe(
RxJs.map((v) => v * 2),
);
mySubj$.subscribe((value) => {
console.log('Original value:', value);
});
doubled$.subscribe((value) => {
console.log('Doubled value:', value);
});
mySubj$.next(1); // Logs:
// ✅ `Original value: 1`
// ✅ `Doubled value: 2`
doubled$.next(3); // Logs:
// ❌ `Original value: 3`
// ❌ `Doubled value: 6`There's an inconsistency in the APIs exposed by doubled$:
.subscribe()applies the observable returned by the.pipe().next()applies to source of the.pipe()(mySubj$).
Expected behavior
I would expect .next() to fail with not a function.
According to the types, .pipe() returns an Observable (where .next() is not available).
Reproduction code
const RxJs = require('rxjs');
const mySubj$ = new RxJs.Subject();
const doubled$ = mySubj$.pipe(
RxJs.map((v) => v * 2),
);
mySubj$.subscribe((value) => {
console.log('Original value:', value);
});
doubled$.subscribe((value) => {
console.log('Doubled value:', value);
});
mySubj$.next(1); // Logs:
// ✅ `Original value: 1`
// ✅ `Doubled value: 2`
doubled$.next(3); // Logs:
// ❌ `Original value: 3`
// ❌ `Doubled value: 6`Reproduction URL
No response
Version
7.8.2
Environment
No response
Additional context
Currently, this is the workaround to achieve this:
const doubled$ = mySubj$.asObservable().pipe(gsoldevilademensky, dariomannu, macksal and mmustra
Metadata
Metadata
Assignees
Labels
No labels