Skip to content

Commit 54c0846

Browse files
authored
feat(Breaking News): Implemented breakingNewsLoaded (#59)
1 parent 0da2969 commit 54c0846

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ This component will automatically fetch breaking news every 30 seconds, and rend
4242

4343
```javascript
4444
import { renderBreakingNews } from '@quintype/framework/client/start';
45-
const BreakingNewsView = (props) => <ul>{props.breakingNews.map((item, index) => <li key={index}><BreakingNewsItem item={item} /></li>)}</ul>
45+
const BreakingNewsView = ({breakingNews, breakingNewsLoaded}) =>
46+
<ul>{breakingNews.map((item, index) => <li key={index}><BreakingNewsItem item={item} /></li>)}</ul>
4647
renderBreakingNews('breaking-news-container', store, BreakingNewsView);
4748
```
4849

src/components/breaking-news.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function mapStateToProps(state) {
2929
return {
3030
config: state.qt.config || {},
3131
breakingNews: state.breakingNews || [],
32+
breakingNewsLoaded: state.breakingNewsLoaded || false,
3233
}
3334
}
3435

src/store/reducers.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,23 @@ import {
1010
MEMBER_BEING_LOADED,
1111
} from './actions';
1212

13-
function breakingNewsReducer(state = [], action) {
14-
switch (action.type) {
15-
case BREAKING_NEWS_UPDATED: return action.stories;
16-
default: return state;
13+
function setToTrueOnEvent() {
14+
const events = Array.from(arguments);
15+
return function(state = false, action) {
16+
return state || events.includes(action.type);
1717
}
1818
}
1919

20-
function clientSideRenderedReducer(state = false, action) {
20+
function breakingNewsReducer(state = [], action) {
2121
switch (action.type) {
22-
case CLIENT_SIDE_RENDERED: return true;
22+
case BREAKING_NEWS_UPDATED: return action.stories;
2323
default: return state;
2424
}
2525
}
2626

27+
const breakingNewsLoadedReducer = setToTrueOnEvent(BREAKING_NEWS_UPDATED);
28+
const clientSideRenderedReducer = setToTrueOnEvent(CLIENT_SIDE_RENDERED);
29+
2730
function pageLoadingReducer(state = false, action) {
2831
switch (action.type) {
2932
case PAGE_LOADING: return true;
@@ -59,6 +62,7 @@ function memberLoadingReducer(state = true, action) {
5962

6063
export const ComponentReducers = {
6164
breakingNews: breakingNewsReducer,
65+
breakingNewsLoaded: breakingNewsLoadedReducer,
6266
clientSideRendered: clientSideRenderedReducer,
6367
pageLoading: pageLoadingReducer,
6468
hamburgerOpened: hamburgerOpenedReducer,

0 commit comments

Comments
 (0)