pipe operator does not work with v6 as before v5
See original GitHub issueRxJS version:
6.0.0-beta.0
Code to reproduce:
import { from } from 'rxjs';
import { concat } from 'rxjs';
import { delay } from 'rxjs/operators';
let $from1 = from([1, 2]);
$from1
.pipe(
delay(2000),
concat(from([3, 4])),
delay(2000)
).subscribe(v => console.log(`$from1-delay-concat: ${v}`));
Expected behavior:
it should run without errors as in v5.5.6
Actual behavior:
/rxjs/node_modules/rxjs/internal/util/pipe.js:22
return fns.reduce(function (prev, fn) { return fn(prev); }, input);
^
TypeError: fn is not a function
at /rxjs/node_modules/rxjs/internal/util/pipe.js:22:56
at Array.reduce (<anonymous>)
at piped (/rxjs/node_modules/rxjs/internal/util/pipe.js:22:20)
at Observable.pipe (rxjs/node_modules/rxjs/internal/Observable.js:252:48)
at Object.<anonymous> (rxjs/lib/index.js:18:25)
at Module._compile (module.js:657:14)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
Additional information:
Its not possible to investigate the issue/problem by my self because i guess the sourcemaps are broken! Could not set a breakpoint e.g. in rxjs/src/internal/util/pipe.ts
. The browser jumps to a blank page (also not working after removing the .js.map and the location to the sourcemap in the related file)
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Multicast Operator with Pipe in RxJS 5.5+ - Stack Overflow
I get a TypeScript error when I try to use connect() like I did before: const even$ = new Subject(); const connectedSub =...
Read more >RxJS 6: What's new and what has changed? - Auth0
Use piping instead of chaining as new operator syntax. The result of one operator is piped into another operator. Don't remove rxjs-compat until ......
Read more >Pipe operator (%>%) does not work - RStudio Community
This is a recurring problem for me - pipe operator from dplyr package doesn't work in many cases. I'm sharing a screen recording....
Read more >RxJS Explorer 2.0 - Reactive
Pipeable operators. Use the pipe method built into Observable . Optionally, import the pipe function to build custom and reusable operators from other...
Read more >Transforming Data Using Pipes - Angular
However, a pure pipe with an array as input might not work the way you want. To demonstrate this issue, change the previous...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I always suggest everyone to read here: https://github.com/ReactiveX/rxjs/blob/master/doc/pipeable-operators.md (at least until rxjs-docs is out)
To do what you want to do I would build my own operator, like so:
To pull it as your own operator
I made a stackblitz on here: https://stackblitz.com/edit/rxjs-issue-3447?file=index.ts
Looking at the previous source of
concat
, I can see the operator was intended to be used together with another observable, such as:Observable1.concat(Observable2)
But the
pipeable operators
are meant to be a function that takes in anobservable
and returns anotherobservable
.So maybe we should make a concat operator that works like so
concat(from([3, 4])
and would applyconcat(source, from([3,4]))
on it under the coversHaving read that (https://github.com/ReactiveX/rxjs/blob/master/doc/pipeable-operators.md) helped me a lot! Thanks for that.
Now i know why this isn’t working anymore! The pipe operator in v6 accepts only function(s) as argument(s). It’s solved totally elegantly (I believe, it’s called closure/currying), one function provides another function and the other provides an observable. The closure/currying pattern was not clear at the first glance.
… and because i am not so familiar with functional programming, i could not interpret the error message immediately.
@claudiordgz Thank you so much, now everything is so clear for me!