Skip to content

Commit 793ccd5

Browse files
committed
now it makes more sense
1 parent d8420cd commit 793ccd5

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
lines changed

src/App.js

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,19 @@ const SUBJECT = {
1313

1414
const App = ({
1515
subject,
16-
query,
17-
stories,
16+
query = '',
17+
stories = [],
1818
onSelectSubject,
1919
onChangeQuery,
2020
}) => (
2121
<div>
22-
<h1>Hacker News with React and Rx.js</h1>
22+
<h1>React with RxJS</h1>
23+
24+
<input
25+
type="text"
26+
value={query}
27+
onChange={event => onChangeQuery(event.target.value)}
28+
/>
2329

2430
<div>
2531
{Object.values(SUBJECT).map(subject => (
@@ -33,11 +39,6 @@ const App = ({
3339
))}
3440
</div>
3541

36-
<input
37-
type="text"
38-
onChange={event => onChangeQuery(event.target.value)}
39-
/>
40-
4142
<p>{`http://hn.algolia.com/api/v1/${subject}?query=${query}`}</p>
4243

4344
<ul>
@@ -53,7 +54,7 @@ const App = ({
5354
);
5455

5556
const subject$ = new BehaviorSubject(SUBJECT.POPULARITY);
56-
const query$ = new BehaviorSubject('');
57+
const query$ = new BehaviorSubject('react');
5758

5859
const queryToFetch$ = query$.pipe(
5960
debounce(() => timer(1000)),
@@ -83,10 +84,4 @@ export default withObservableStream(
8384
onSelectSubject: subject => subject$.next(subject),
8485
onChangeQuery: value => query$.next(value),
8586
},
86-
// initial state
87-
{
88-
subject: SUBJECT.POPULARITY,
89-
query: '',
90-
stories: [],
91-
},
9287
)(App);

src/withObservableStream.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,11 @@ import React from 'react';
22

33
export default (observables, actions, initialState) => Component => {
44
return class extends React.Component {
5-
constructor(props) {
6-
super(props);
7-
8-
this.state = { ...initialState };
9-
}
10-
115
componentDidMount() {
126
this.subscriptions = observables.map(observable =>
13-
observable.subscribe(newState =>
14-
this.setState({ ...newState }),
7+
observable.subscribe(
8+
newState =>
9+
console.log(newState) || this.setState({ ...newState }),
1510
),
1611
);
1712
}

0 commit comments

Comments
 (0)