Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,260 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,6 +1,8 @@ | |||
import { combineReducers } from 'redux' | import { combineReducers } from 'redux' | ||
import { posts } from './posts' | import { posts } from './posts' | ||
import { inited } from './inited' | |||
|
|
||
export const root = combineReducers({ | export const root = combineReducers({ | ||
posts | posts, | ||
inited | |||
}) | }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
import { RECEIVE_POSTS, ERROR_POSTS } from '../actions' | |||
|
|||
export function inited (state = false, action) { | |||
switch (action.type) { | |||
case RECEIVE_POSTS: | |||
case ERROR_POSTS: | |||
return true | |||
default: | |||
return state | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,23 @@ | |||
import React from 'react' | |||
import { createStore } from 'redux' | |||
import { root } from './reducers' | |||
import { receivePosts, errorPosts } from './actions' | |||
import { Provider } from 'react-redux' | |||
import { renderToString } from 'react-dom/server' | |||
import { App } from './App' | |||
|
|||
export function renderToStrings (posts) { | |||
const store = createStore(root) | |||
store.dispatch( | |||
posts ? receivePosts(posts) : errorPosts() | |||
) | |||
|
|||
const html = renderToString( | |||
<Provider store={store}> | |||
<App /> | |||
</Provider> | |||
) | |||
const state = JSON.stringify(JSON.stringify(store.getState())) | |||
|
|||
return { html, state } | |||
} |
Oops, something went wrong.