Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- console.clear();
- import {
- combineLatest,
- forkJoin,
- from,
- fromEvent,
- iif,
- interval,
- merge,
- of,
- timer
- } from "rxjs";
- import { ajax } from "rxjs/ajax";
- import {
- buffer,
- catchError,
- debounceTime,
- delay,
- distinct,
- distinctUntilChanged,
- distinctUntilKeyChanged,
- filter,
- first,
- last,
- map,
- mergeAll,
- mergeMap,
- reduce,
- retry,
- scan,
- skip,
- skipWhile,
- take,
- takeUntil,
- takeWhile,
- tap,
- toArray,
- withLatestFrom
- } from "rxjs/operators";
- const input$ = fromEvent(document.getElementById("myInput"), "input").pipe(
- map(ev => (ev.currentTarget as HTMLInputElement).value)
- );
- const role$ = of("admin");
- const theme$ = of("dark");
- fromEvent(document, "click")
- .pipe(
- mergeMap(val => ajax.get("https://jsonplaceholder.typicode.com/posts")),
- map(res => res.response),
- mergeMap(posts =>
- combineLatest(role$, theme$).pipe(
- map(val => ({ role: val[0], theme: val[1], result: posts }))
- )
- ),
- mergeMap(obj => {
- return iif(
- () => obj.role === "admin",
- ajax.get(
- "https://jsonplaceholder.typicode.com/comments?postId=" +
- obj.result[0].id
- ),
- ajax.post("https://jsonplaceholder.typicode.com/comments", {})
- );
- /*
- if (obj.role === "admin") {
- return ajax.get("https://jsonplaceholder.typicode.com/comments?postId=" +
- obj.result[0].id)
- } else {
- return ajax.post("https://jsonplaceholder.typicode.com/comments", {})
- }
- */
- }),
- map(res => res.response)
- )
- .subscribe(
- res => console.log(res),
- err => console.log("err", err),
- () => console.log("completed")
- );
- const users = [1, 2, 3];
- const total = users.reduce((acc, curr) => acc + curr, 0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement