From 3183e8e931a1741447dc39fa49de5eb668d51568 Mon Sep 17 00:00:00 2001 From: jmarceli Date: Sun, 18 Oct 2015 11:56:31 +0200 Subject: [PATCH 1/3] Create docs/recipes/MigratingToES7.md --- docs/recipes/MigratingToES7.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 docs/recipes/MigratingToES7.md diff --git a/docs/recipes/MigratingToES7.md b/docs/recipes/MigratingToES7.md new file mode 100644 index 0000000000..e69de29bb2 From 29279c9d5a8f458d608bf4971a16e6d917c8aa95 Mon Sep 17 00:00:00 2001 From: jmarceli Date: Sun, 18 Oct 2015 12:21:01 +0200 Subject: [PATCH 2/3] Update docs/recipes/MigratingToES7.md --- docs/recipes/MigratingToES7.md | 81 ++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/docs/recipes/MigratingToES7.md b/docs/recipes/MigratingToES7.md index e69de29bb2..5407796915 100644 --- a/docs/recipes/MigratingToES7.md +++ b/docs/recipes/MigratingToES7.md @@ -0,0 +1,81 @@ +# Migrating to ES7 + +If you like ES7 syntactic sugar you can use it with Redux! + +## mapStateToProps() -> @connect + +Example based on "Todo List" app + +**ES6**: + +```js +class App extends Component { +... +} + +function mapStateToProps(state) { + return { + visibleTodos: selectTodos(state.todos, state.visibilityFilter), + visibilityFilter: state.visibilityFilter + }; +} + +export default connect(select)(App); + +``` + +**ES7**: + +```js +@connect(state => ({ + visibleTodos: selectTodos(state.todos, state.visibilityFilter), + visibilityFilter: state.visibilityFilter +})) +export default class App extends Component { +... +} + +``` + +## component propTypes -> static + +Example based on "Todo List" app + +**ES6**: +```js +class App extends Component { +... +} + +App.propTypes = { + visibleTodos: PropTypes.arrayOf(PropTypes.shape({ + text: PropTypes.string.isRequired, + completed: PropTypes.bool.isRequired + })), + visibilityFilter: PropTypes.oneOf([ + 'SHOW_ALL', + 'SHOW_COMPLETED', + 'SHOW_ACTIVE' + ]).isRequired +}; + +``` + +**ES7**: +```js +class App extends Component { + static propTypes = { + visibleTodos: PropTypes.arrayOf(PropTypes.shape({ + text: PropTypes.string.isRequired, + completed: PropTypes.bool.isRequired + })), + visibilityFilter: PropTypes.oneOf([ + 'SHOW_ALL', + 'SHOW_COMPLETED', + 'SHOW_ACTIVE' + ]).isRequired + }; + ... +} + +``` \ No newline at end of file From cd008ee2696e7dd745b896bc0542f0912e3dca81 Mon Sep 17 00:00:00 2001 From: jmarceli Date: Sun, 18 Oct 2015 12:22:34 +0200 Subject: [PATCH 3/3] Update docs/recipes/README.md --- docs/recipes/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/recipes/README.md b/docs/recipes/README.md index d8b5dc6ddc..3c83c8f16f 100644 --- a/docs/recipes/README.md +++ b/docs/recipes/README.md @@ -8,4 +8,4 @@ These are some use cases and code snippets to get you started with Redux in a re * [Writing Tests](WritingTests.md) * [Computing Derived Data](ComputingDerivedData.md) * [Implementing Undo History](ImplementingUndoHistory.md) - +* [Migrating to ES7](MigratingToES7.md)