Skip to content
This repository was archived by the owner on Jul 12, 2019. It is now read-only.

Commit 6fd2450

Browse files
committed
More paradigmatic usage of streams
1 parent 651955b commit 6fd2450

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/view/home/HomePage.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import { SearchBar } from './SearchBar.js';
77
import { ResultsContainer } from './ResultsContainer.js';
88

99
export function HomePage(sources) {
10-
const discoveryModePredicate =
11-
phrase => phrase.length === 0;
12-
1310
const {
1411
DOM: searchBarVdom$,
1512
HTTP: searchBarHttp$,
@@ -19,6 +16,10 @@ export function HomePage(sources) {
1916
isError$: searchIsError$
2017
} = SearchBar(sources);
2118

19+
const isDiscoveryMode$ =
20+
searchPhrase$
21+
.map(phrase => phrase.length === 0);
22+
2223
const discoveryRequest$ =
2324
xs.of({
2425
url: sources.SvcUrl(`/movie/popular?language=en-US&page=1`),
@@ -37,9 +38,9 @@ export function HomePage(sources) {
3738
.startWith('')
3839

3940
const content$ =
40-
xs.combine(searchPhrase$, searchResponse$, discoveryResponse$)
41-
.map(([searchPhrase, searchResponse, discoveryResponse]) =>
42-
discoveryModePredicate(searchPhrase)
41+
xs.combine(isDiscoveryMode$, searchResponse$, discoveryResponse$)
42+
.map(([isDiscoveryMode, searchResponse, discoveryResponse]) =>
43+
isDiscoveryMode
4344
? discoveryResponse
4445
: searchResponse
4546
)
@@ -68,16 +69,16 @@ export function HomePage(sources) {
6869
});
6970

7071
const vdom$ =
71-
xs.combine(searchBarVdom$, searchPhrase$, resultsVdom$)
72-
.map(([searchBarVdom, searchPhrase, resultsVdom]) =>
72+
xs.combine(searchBarVdom$, isDiscoveryMode$, searchPhrase$, resultsVdom$)
73+
.map(([searchBarVdom, isDiscoveryMode, searchPhrase, resultsVdom]) =>
7374
<div className="HomePage">
7475
<h1>TMDb UI – Home</h1>
7576
<legend className="uk-legend">Search for a Title:</legend>
7677

7778
{searchBarVdom}
7879

7980
<h3 className="uk-heading-bullet uk-margin-remove-top">
80-
{discoveryModePredicate(searchPhrase)
81+
{isDiscoveryMode
8182
? 'Popular Now'
8283
: `Search Results for "${searchPhrase}":`}
8384
</h3>

0 commit comments

Comments
 (0)