You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 4, 2017. It is now read-only.
`ValueChanges` is an observable that represents text changes triggered by typing into the search textbox.
409
+
### asObservable
410
+
We start the observable chain by calling `asObservable` on our `Subject` to return an observable that represents text changes as we are typing into the search box.
404
411
405
412
### debounceTime(300)
406
413
By specifying a debounce time of 300 ms we are telling `RxJs` that we only want to be notified of key events after intervals of 300 ms. This is a performance measure meant to prevent us from hitting the api too often with partial search queries.
407
414
408
415
### distinctUntilChanged
409
416
`distinctUntilChanged` tells `RxJs` to only react if the value of the textbox actually changed.
410
417
411
-
### do
412
-
`do` is an operator for triggering side effects outside the observable chain. In our case we are using it to set a flag to hide the search results if the search textbox is empty.
413
-
414
-
### filter
415
-
By specifying a `filter` we are telling `RxJs` to only process search values that meet our filter condition.
416
-
417
418
### switchMap
418
419
`switchMap` is where observables from key events and observables from http calls converge on a single observable.
419
420
420
421
Every qualifying key event will trigger an http call, so we may get into a situation where we have multiple http calls in flight.
421
422
422
423
Normally this could lead to results being returned out of order, but `switchMap` has built in support for ensuring that only the most recent http call will be processed. Results from prior calls will be discarded.
423
424
425
+
We short circuit the http call and return an observable containing an empty array if the search box is empty.
426
+
424
427
### subscribe
425
428
`subscribe` is similar to `then` in the promise world.
426
429
@@ -431,7 +434,7 @@ block heroes-comp-add
431
434
In our current implementation we are just logging the error to the console, but a real life application should do better.
432
435
433
436
### Import operators
434
-
These operators we are not included by default, so we have to load each one using `import` statements.
437
+
The `RxJs` operators are not included by default, so we have to include them using `import` statements.
435
438
436
439
We have combined all operator imports in a single file.
0 commit comments