-
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
1 parent
a34331f
commit aa3468b
Showing
9 changed files
with
161 additions
and
9 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
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
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 @@ | ||
<p>promesas works!</p> |
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,38 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-promesas', | ||
templateUrl: './promesas.component.html', | ||
styles: [] | ||
}) | ||
export class PromesasComponent implements OnInit { | ||
|
||
constructor() { | ||
|
||
this.contar3().then ( | ||
// () => console.log ('Termino') | ||
mensaje => console.log ('Termino', mensaje) | ||
) | ||
.catch ( error => console.log ('Error')); | ||
} | ||
|
||
ngOnInit() { | ||
} | ||
|
||
contar3() { | ||
|
||
return new Promise( (resolve, reject) => { | ||
let contador = 0; | ||
const intervalo = setInterval( () => { | ||
contador += 1; | ||
console.log (contador); | ||
if ( contador === 3) { | ||
resolve('OK!'); | ||
// reject('Soy el texto del error'); | ||
clearInterval( intervalo); | ||
} | ||
}, 1000); | ||
}); | ||
|
||
} | ||
} |
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 @@ | ||
<p>rxjs works!</p> |
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,76 @@ | ||
import { Component, OnInit, OnDestroy } from '@angular/core'; | ||
// tslint:disable-next-line: import-blacklist | ||
import { Observable, Subscriber, Subscription } from 'rxjs'; | ||
import { retry, map , filter} from 'rxjs/operators'; | ||
|
||
@Component({ | ||
selector: 'app-rxjs', | ||
templateUrl: './rxjs.component.html', | ||
styles: [] | ||
}) | ||
export class RxjsComponent implements OnInit, OnDestroy { | ||
|
||
suscripction: Subscription; | ||
|
||
constructor() { | ||
|
||
this.suscripction = this.regresaObservable() | ||
// .pipe( | ||
// retry(2) | ||
// ) | ||
.subscribe( | ||
numero => console.log('Subs ', numero), | ||
error => console.error ('Error'), | ||
() => console.log('El observador termino') | ||
); | ||
} | ||
|
||
|
||
|
||
ngOnInit() { | ||
} | ||
|
||
ngOnDestroy() { | ||
console.log( 'Me voy del componente'); | ||
this.suscripction.unsubscribe(); | ||
} | ||
|
||
regresaObservable(): Observable<any> { | ||
|
||
return new Observable ( (observer: Subscriber<any>) => { | ||
|
||
let contador = 1; | ||
|
||
const intervalo = setInterval ( () => { | ||
contador ++; | ||
|
||
const salida = { | ||
valor: contador | ||
}; | ||
observer.next(salida); | ||
|
||
// if ( contador === 3) { | ||
// clearInterval(intervalo); | ||
// observer.complete(); | ||
// } | ||
|
||
// if ( contador === 2) { | ||
// // clearInterval(intervalo); | ||
// observer.error('Auxilio!!!'); | ||
// } | ||
|
||
}, 1000); | ||
}).pipe( | ||
map( resp => resp.valor), | ||
filter ( (valor, index) => { | ||
if ( ( valor % 2) === 1) { | ||
// Numero impar | ||
return true; | ||
} else { | ||
// Numero par | ||
return false; | ||
} | ||
}) | ||
); | ||
} | ||
} |
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
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
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