Created
January 30, 2018 11:59
-
-
Save RichardSilveira/705ba8ff7d3a643a2c1b7f8364f85194 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* Caso comum de uso dos Observables, sendo retornado por uma função que faz | |
chamadas assíncronas (requisições http). | |
Código exemplifica como é a criação "explícita" de um Observable, | |
mas existem outros métodos que fazem isso por você, | |
como Rx.Observable.of(<SeuObjetoRetornado>)*/ | |
const obterRecursoDaApi = Rx.Observable.create(observer => { | |
setTimeout(() => { | |
observer.next([{id: 1, titulo: 'algum título'}, {id: 2, titulo: 'outro título'}]); | |
observer.complete(); | |
}, 1000) | |
}) | |
// Implementando apenas o callback 'next' do Observer | |
obterRecursoDaApi.subscribe(resp => console.log(JSON.stringify(resp))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment