Skip to content

Commit

Permalink
docs(tutorial): Log target values and not the events
Browse files Browse the repository at this point in the history
We want to log the input values and not the keypress events.
  • Loading branch information
jtefera authored Dec 31, 2016
1 parent 6922b16 commit 0ab524e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions doc/tutorial/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,33 @@ var input = Rx.Observable.fromEvent(document.querySelector('input'), 'keypress')

// Filter out target values less than 3 characters long
input.filter(event => event.target.value.length > 2)
.map(event => event.target.value)
.subscribe(value => console.log(value)); // "hel"

// Delay the events
input.delay(200)
.map(event => event.target.value)
.subscribe(value => console.log(value)); // "h" -200ms-> "e" -200ms-> "l" ...

// Only let through an event every 200 ms
input.throttleTime(200)
.map(event => event.target.value)
.subscribe(value => console.log(value)); // "h" -200ms-> "w"

// Let through latest event after 200 ms
input.debounceTime(200)
.map(event => event.target.value)
.subscribe(value => console.log(value)); // "o" -200ms-> "d"

// Stop the stream of events after 3 events
input.take(3)
.map(event => event.target.value)
.subscribe(value => console.log(value)); // "hel"

// Passes through events until other observable triggers an event
var stopStream = Rx.Observable.fromEvent(document.querySelector('button'), 'click');
input.takeUntil(stopStream)
.map(event => event.target.value)
.subscribe(value => console.log(value)); // "hello" (click)
```

Expand Down

0 comments on commit 0ab524e

Please sign in to comment.