-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alex Ortigosa
committed
Oct 3, 2021
1 parent
6d5618b
commit 9a3fba7
Showing
7 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { of } from 'rxjs'; | ||
import { startWith, endWith} from 'rxjs/operators'; | ||
|
||
const numeros$ = of(1,2,3).pipe( | ||
startWith('a','b','c'), | ||
endWith('x','y','z') | ||
); | ||
|
||
numeros$.subscribe(console.log); |
22 changes: 22 additions & 0 deletions
22
src/operadores-combinacion/02-lab-startWith-loadingBackground.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { ajax } from 'rxjs/ajax'; | ||
import { startWith } from 'rxjs/operators'; | ||
// Referencias | ||
const loadingDiv = document.createElement('div'); | ||
loadingDiv.classList.add('loading'); | ||
loadingDiv.innerHTML = 'Cargando'; | ||
|
||
const body = document.body; | ||
|
||
// Stream | ||
ajax.getJSON('https://reqres.in/api/users/2?delay=3').pipe( | ||
startWith(true) | ||
).subscribe( resp => { | ||
|
||
if(resp === true){ | ||
body.append(loadingDiv); | ||
} else { | ||
document.querySelector('.loading').remove(); | ||
} | ||
|
||
console.log(resp) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { concat, interval } from 'rxjs'; | ||
import { take } from 'rxjs/operators'; | ||
|
||
const interval$ = interval(1000); | ||
|
||
concat( | ||
interval$.pipe(take(3)), | ||
interval$.pipe(take(2)), | ||
[1,2,3,4] | ||
).subscribe(console.log) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { fromEvent, merge } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
|
||
const keyup$ = fromEvent(document,'keyup'); | ||
const click$ = fromEvent(document,'click'); | ||
|
||
merge( | ||
keyup$.pipe(map(e => e.type)), | ||
click$.pipe(map(e => e.type)) | ||
).subscribe(console.log) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { combineLatest, fromEvent, merge } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
|
||
const input1 = document.createElement('input'); | ||
const input2 = document.createElement('input'); | ||
|
||
input1.placeholder = 'email@gmail.com'; | ||
|
||
input2.placeholder = '*******'; | ||
input2.type = 'password'; | ||
|
||
document.body.append(input1, input2); | ||
|
||
// Helper | ||
const getInputStream = (elem: HTMLElement) => { | ||
return fromEvent<KeyboardEvent>(elem, 'keyup').pipe( | ||
map(e => e.target['value']) | ||
); | ||
} | ||
|
||
|
||
combineLatest([ | ||
getInputStream(input1), | ||
getInputStream(input2) | ||
]).subscribe(console.log) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { of, interval, forkJoin } from 'rxjs'; | ||
import { delay, take } from 'rxjs/operators'; | ||
|
||
const numeros$ = of(1,2,3,4); | ||
const intervalo$ = interval(1000).pipe(take(3)); | ||
const letras$ = of('a','b','c').pipe(delay(3500)); | ||
|
||
// forkJoin([ | ||
// numeros$, | ||
// intervalo$, | ||
// letras$ | ||
// ]).subscribe(console.log); | ||
|
||
|
||
// Dificil de leer | ||
// | ||
// forkJoin([ | ||
// numeros$, | ||
// intervalo$, | ||
// letras$ | ||
// ]).subscribe( resp => { | ||
// console.log('numeros:', resp[0]) | ||
// console.log('intervalo:', resp[1]) | ||
// console.log('letras:', resp[2]) | ||
// }); | ||
|
||
// forkJoin({ | ||
// numeros$, | ||
// intervalo$, | ||
// letras$ | ||
// }).subscribe( resp => { | ||
// console.log(resp) | ||
// }); | ||
|
||
forkJoin({ | ||
num: numeros$, | ||
int: intervalo$, | ||
let: letras$ | ||
}).subscribe( resp => { | ||
console.log(resp) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { forkJoin, of } from 'rxjs'; | ||
import { ajax } from 'rxjs/ajax'; | ||
import { catchError } from 'rxjs/operators'; | ||
|
||
const GITHUB_API_URL = 'https://api.github.com/users'; | ||
const GITHUB_USER = 'alesyt0h'; | ||
|
||
forkJoin({ | ||
usuario: ajax.getJSON(`${GITHUB_API_URL}/${GITHUB_USER}`), | ||
repos: ajax.getJSON(`${GITHUB_API_URL}/${GITHUB_USER}/repo123123s`).pipe(catchError(err => of([]))), | ||
gists: ajax.getJSON(`${GITHUB_API_URL}/${GITHUB_USER}/gists`), | ||
}).pipe( | ||
catchError( err => of(err.message)) | ||
).subscribe(console.log); |