Skip to content

Instantly share code, notes, and snippets.

@raloliver
Created September 12, 2019 15:42
Show Gist options
  • Save raloliver/ee2bc72c3d834dd56cdcfe5c62835cb5 to your computer and use it in GitHub Desktop.
Save raloliver/ee2bc72c3d834dd56cdcfe5c62835cb5 to your computer and use it in GitHub Desktop.
RxJS: delay, interval, timer, debounce
//5 segundos após a inscrição
var sourceHoldOn = Rx.Observable.from([1,2,3,4,5]).delay(5000);
var subscriptionHoldOn = source.subscribe(
value => console.log(value)
);
//utilize o método take() para limitar quantos deseja receber
var sourceInterval = Rx.Observable.interval(1000)
var subscriptionInterval = source.subscribe(
value => console.log(value)
);
//delay() and interval() together mix with take()
var sourceTimer = Rx.Observable.timer(5000, 1000).take(5)
var subscriptionTimer = source.subscribe(
value => console.log(value)
);
//dispara o valor após determinado tempo: recebe uma função que deve retornar um intervalo
inputs = Rx.Observable.fromEvent(myInput, 'keyup');
inputs.debounce(()=> Rx.Observable.interval(1000)).subscribe(event => {
myDiv.innerHTML = event.target.value;
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment