-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: SSR + Code Splitting 🚀 (#43)
* multi: Prepare for code splitting chore: Add react-loadable to dependencies chore: Move babel options to package.json so they can be retrieved more easily in webpack config chore: Remove webpack patch (https://github.com/gaearon/react-hot-loader/tree/next\#no-patch-required) chore: Update dependencies, move appropriate to devDependencies * feat: split up todos into separate components * chore: move templates to server folder instead * feat: SSR + code splitting 🚀 - Add support for import() syntax in babel and use only on the server (it is already supported on the client with webpack 2) - Update webpack config for import() code splitting - Fix an issue with static fetching for server data * chore: update readme/comments
- Loading branch information
Showing
36 changed files
with
2,776 additions
and
1,104 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,5 @@ npm-debug.log* | |
# ignore built static files | ||
/dist | ||
/webpack-assets.json | ||
/webpack-stats.json | ||
/react-loadable.json |
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 | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,30 @@ | ||
import 'babel-polyfill'; | ||
import 'css/base/index.scss'; | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { Provider } from 'react-redux'; | ||
import { ConnectedRouter } from 'react-router-redux'; | ||
import createHistory from 'history/createBrowserHistory'; | ||
import configureStore from 'store'; | ||
import App from 'containers/App'; | ||
import Loadable from 'react-loadable'; | ||
|
||
import './styles'; | ||
|
||
// Hydrate the redux store from server state. | ||
const initialState = window.__INITIAL_STATE__; | ||
const history = createHistory(); | ||
const store = configureStore(initialState, history); | ||
|
||
// Render the application | ||
ReactDOM.hydrate( | ||
<Provider store={store}> | ||
<ConnectedRouter history={history}> | ||
<App /> | ||
</ConnectedRouter> | ||
</Provider>, | ||
document.getElementById('app') | ||
); | ||
window.main = () => { | ||
Loadable.preloadReady().then(() => { | ||
ReactDOM.hydrate( | ||
<Provider store={store}> | ||
<ConnectedRouter history={history}> | ||
<App /> | ||
</ConnectedRouter> | ||
</Provider>, | ||
document.getElementById('app') | ||
); | ||
}); | ||
}; |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Include all Vendor CSS here | ||
import 'semantic-ui-css/semantic.min.css'; | ||
|
||
// Base styles | ||
import 'css/base/index.scss'; |
This file was deleted.
Oops, something went wrong.
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const Loading = (props) => { | ||
const { error, timedOut, pastDelay } = props; | ||
|
||
console.log(props); | ||
|
||
if (error) { | ||
// When the loader has errored | ||
return ( | ||
<div>Error!</div> | ||
); | ||
} else if (timedOut) { | ||
// When the loader has taken longer than the timeout | ||
return ( | ||
<div>Taking a long time...</div> | ||
); | ||
} else if (pastDelay) { | ||
// When the loader has taken longer than the delay | ||
return ( | ||
<div>Loading...</div> | ||
); | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
Loading.propTypes = { | ||
error: PropTypes.bool, | ||
timedOut: PropTypes.bool, | ||
pastDelay: PropTypes.bool | ||
}; | ||
|
||
export default Loading; |
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 | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export { default as ErrorPage } from './ErrorPage'; | ||
export { default as Footer } from './Footer'; | ||
export { default as Header } from './Header'; | ||
export { default as Loading } from './Loading'; | ||
export { default as RouteWithSubRoutes } from './RouteWithSubRoutes'; |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Form } from 'semantic-ui-react'; | ||
import classnames from 'classnames/bind'; | ||
import css from './index.scss'; | ||
|
||
class TodoForm extends Component { | ||
static propTypes = { | ||
onSubmit: PropTypes.func, | ||
className: PropTypes.string | ||
}; | ||
|
||
state = { todoText: '' }; | ||
|
||
submitTodo = ev => { | ||
ev.preventDefault(); | ||
|
||
const { onSubmit } = this.props; | ||
const { todoText } = this.state; | ||
|
||
if (todoText && todoText !== '' && typeof onSubmit === 'function') { | ||
onSubmit(todoText); | ||
this.setState({ todoText: '' }); | ||
} | ||
}; | ||
|
||
onTodoChange = ev => { | ||
this.setState({ todoText: ev.target.value }); | ||
}; | ||
|
||
render() { | ||
const { className } = this.props; | ||
const { todoText } = this.state; | ||
|
||
return ( | ||
<Form | ||
className={classnames(css.todoForm, className)} | ||
onSubmit={this.submitTodo} | ||
> | ||
<Form.Group> | ||
<Form.Input | ||
onChange={this.onTodoChange} | ||
value={todoText} | ||
type="text" | ||
placeholder="Add a todo..." | ||
/> | ||
<Form.Button content="Add" icon="plus" /> | ||
</Form.Group> | ||
</Form> | ||
); | ||
} | ||
} | ||
|
||
export default TodoForm; |
Empty file.
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { List, Checkbox, Button } from 'semantic-ui-react'; | ||
import classnames from 'classnames/bind'; | ||
import css from './index.scss'; | ||
|
||
const cx = classnames.bind(css); | ||
|
||
const TodoItem = props => { | ||
const { onRemove, onChange, todo: { id, completed, text } } = props; | ||
|
||
return ( | ||
<List.Item className={classnames(css.todo, css.extra)}> | ||
<List.Content floated="right"> | ||
<Button onClick={() => onRemove(id)} icon="remove" size="mini" /> | ||
</List.Content> | ||
<List.Content floated="left"> | ||
<Checkbox | ||
type="checkbox" | ||
checked={completed} | ||
onChange={() => onChange(id)} | ||
/> | ||
</List.Content> | ||
<List.Content className={cx(css.text, { [css.completed]: completed })}> | ||
{text} | ||
</List.Content> | ||
</List.Item> | ||
); | ||
}; | ||
|
||
TodoItem.propTypes = { | ||
todo: PropTypes.object.isRequired, | ||
onRemove: PropTypes.func, | ||
onChange: PropTypes.func | ||
}; | ||
|
||
TodoItem.defaultProps = { | ||
onRemove: () => {}, | ||
onChange: () => {} | ||
}; | ||
|
||
export default TodoItem; |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
.todo { | ||
&.extra { | ||
padding: 10px; | ||
} | ||
|
||
.completeInput {} | ||
|
||
.text { | ||
&.completed { | ||
text-decoration: line-through; | ||
color: #ccc; | ||
} | ||
} | ||
|
||
.delete { | ||
cursor: pointer; | ||
color: blue; | ||
text-decoration: underline | ||
} | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { List } from 'semantic-ui-react'; | ||
import { TodoItem } from 'components/todos'; | ||
import classnames from 'classnames'; | ||
import css from './index.scss'; | ||
|
||
const TodoList = props => { | ||
const { className, onChange, onRemove, todos: { todos } } = props; | ||
|
||
return ( | ||
<List divided className={classnames(css.todos, className)}> | ||
{todos.map((todo, idx) => ( | ||
<TodoItem | ||
key={idx} | ||
todo={todo} | ||
onRemove={onRemove} | ||
onChange={onChange} | ||
/> | ||
))} | ||
</List> | ||
); | ||
}; | ||
|
||
TodoList.propTypes = { | ||
todos: PropTypes.object.isRequired, | ||
className: PropTypes.string, | ||
onChange: PropTypes.func, | ||
onRemove: PropTypes.func | ||
}; | ||
|
||
export default TodoList; |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.todos { | ||
width: 300px; | ||
margin: 0; | ||
padding: 0; | ||
list-style: none; | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { default as TodoForm } from './TodoForm'; | ||
export { default as TodoItem } from './TodoItem'; | ||
export { default as TodoList } from './TodoList'; |
Oops, something went wrong.