From 1f7602cf99f56315cb488c0594df086850c89652 Mon Sep 17 00:00:00 2001 From: MrEfrem Date: Tue, 29 Nov 2016 22:10:45 +0400 Subject: [PATCH] Update docs. Publish examples on pages.github. --- .gitignore | 1 + README.md | 7 ++++--- docs/API.md | 17 +++++++++++++++++ examples/async/package.json | 9 +++++++-- examples/async/src/index.js | 7 +++---- examples/counter/package.json | 9 +++++++-- examples/counter/src/index.js | 7 +++---- examples/nested_reused_components/package.json | 9 +++++++-- examples/nested_reused_components/src/index.js | 7 +++---- examples/reused_components/package.json | 9 +++++++-- examples/reused_components/src/index.js | 7 +++---- examples/universal/package.json | 2 +- package.json | 5 +++-- 13 files changed, 66 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index a3ab034..a432044 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ dist lib es coverage +yarn.lock diff --git a/README.md b/README.md index 6a42a13..8deb819 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Redux-fly -The library is focused on to create simple API for: +The library is focused on to providing simple API for: * Reducers registration at any time to any place in store of Redux. * Fast creation and mutation of component state (similar to local state) which is saved in store of Redux. @@ -110,7 +110,7 @@ export default compose( registerReducers({ 'ui counter': reducer }), - connect((state) => ({ counter: state.ui.counter }), actionCreators) + connect((state) => ({ counter: state.ui.counter.value }), actionCreators) )(Counter); ``` @@ -134,7 +134,8 @@ If you don’t yet use npm or a modern module bundler, and would rather prefer a * [`getState(mountPath)(state)`](docs/API.md#getstatemountpathstate) * [`registerReducers(reducers)`](docs/API.md#registerreducersreducers) -## Examples +## Examples ([view](https://mrefrem.github.io/)) +All examples use [redux-devtools-extension](https://github.com/zalmoxisus/redux-devtools-extension) if it is installed in browser. * [Counter](examples/counter). Example to use `redux-fly` component state. * [Async](examples/async). Example to use of mix canonical reducer and `redux-fly` component state. * [Universal](examples/universal). Example to use `redux-fly` for creation of component state and showin how to implement the universal rendering. diff --git a/docs/API.md b/docs/API.md index 716e49c..03ffea0 100644 --- a/docs/API.md +++ b/docs/API.md @@ -72,6 +72,11 @@ ReactDOM.render( ### `enhanceStore` Function enhance an object of Redux store with the `registerReducers` method for gradual registration of reducer at any nesting level of Redux store. +#### `store.registerReducers(reducers)` +* `reducers`\(*Object*) + * `key`\(*string*): it defines reducer mounting path. Argument consist from object keys separated by spaces. + * `value`\(*Function*): it defines reducer. + #### Example Creation of enhanced store: ```javascript @@ -100,6 +105,18 @@ Creation of enhanced store and reducers registration with preloaded state: const store = createStore(reducers, window.__INITIAL_STATE__, enhanceStore); ``` +
+Creation of enhanced store and registration of reducers later: +```javascript +import { createStore } from 'redux'; +import { enhanceStore } from 'redux-fly'; + +const store = createStore(null, enhanceStore); +... +const reducer = (state, action) => { ... }; +store.registerReducers({ 'ui component': reducer }); +``` + ### `getState(mountPath)(state)` Function to extract part of Redux state through mounting path. diff --git a/examples/async/package.json b/examples/async/package.json index 97e6893..a534437 100644 --- a/examples/async/package.json +++ b/examples/async/package.json @@ -1,11 +1,15 @@ { "name": "async", "version": "0.1.0", + "homepage": "https://mrefrem.github.io/async", "private": true, "devDependencies": { + "cpx": "^1.5.0", "enzyme": "^2.6.0", + "gh-pages": "^0.12.0", "react-addons-test-utils": "^15.3.2", - "react-scripts": "0.7.0" + "react-scripts": "0.7.0", + "rimraf": "^2.5.4" }, "dependencies": { "react": "^15.3.2", @@ -20,6 +24,7 @@ "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test --env=jsdom", - "eject": "react-scripts eject" + "eject": "react-scripts eject", + "deploy": "npm run build && cpx \"build/**\" gh-pages/async && gh-pages -d gh-pages -r https://github.com/MrEfrem/mrefrem.github.io.git -b master -v async && rimraf gh-pages" } } diff --git a/examples/async/src/index.js b/examples/async/src/index.js index 8ffd883..92dfb04 100644 --- a/examples/async/src/index.js +++ b/examples/async/src/index.js @@ -7,10 +7,9 @@ import { enhanceStore } from 'redux-fly' import thunk from 'redux-thunk' const composeEnhancers = - process.env.NODE_ENV !== 'production' && - typeof window === 'object' && - window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? - window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({}) : compose + typeof window === 'object' && + window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? + window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({}) : compose const store = createStore(null, composeEnhancers(enhanceStore, applyMiddleware(thunk))) const target = document.getElementById('root') diff --git a/examples/counter/package.json b/examples/counter/package.json index 5aba2ef..a2de33b 100644 --- a/examples/counter/package.json +++ b/examples/counter/package.json @@ -1,11 +1,15 @@ { "name": "counter", "version": "0.1.0", + "homepage": "https://mrefrem.github.io/counter", "private": true, "devDependencies": { + "cpx": "^1.5.0", "enzyme": "^2.6.0", + "gh-pages": "^0.12.0", "react-addons-test-utils": "^15.3.2", - "react-scripts": "0.7.0" + "react-scripts": "0.7.0", + "rimraf": "^2.5.4" }, "dependencies": { "react": "^15.3.2", @@ -19,6 +23,7 @@ "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test --env=jsdom", - "eject": "react-scripts eject" + "eject": "react-scripts eject", + "deploy": "npm run build && cpx \"build/**\" gh-pages/counter && gh-pages -d gh-pages -r https://github.com/MrEfrem/mrefrem.github.io.git -b master -v counter && rimraf gh-pages" } } diff --git a/examples/counter/src/index.js b/examples/counter/src/index.js index 45a6e81..896fa2a 100644 --- a/examples/counter/src/index.js +++ b/examples/counter/src/index.js @@ -6,10 +6,9 @@ import { Provider } from 'react-redux' import { enhanceStore } from 'redux-fly' const composeEnhancers = - process.env.NODE_ENV !== 'production' && - typeof window === 'object' && - window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? - window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({}) : compose + typeof window === 'object' && + window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? + window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({}) : compose const store = createStore(null, composeEnhancers(enhanceStore)) const target = document.getElementById('root') diff --git a/examples/nested_reused_components/package.json b/examples/nested_reused_components/package.json index 83aa485..f529c6a 100644 --- a/examples/nested_reused_components/package.json +++ b/examples/nested_reused_components/package.json @@ -2,10 +2,14 @@ "name": "nested_reused_components", "version": "0.1.0", "private": true, + "homepage": "https://mrefrem.github.io/nested-reused-components", "devDependencies": { + "cpx": "^1.5.0", "enzyme": "^2.6.0", + "gh-pages": "^0.12.0", "react-addons-test-utils": "^15.3.2", - "react-scripts": "0.7.0" + "react-scripts": "0.7.0", + "rimraf": "^2.5.4" }, "dependencies": { "react": "^15.3.2", @@ -20,6 +24,7 @@ "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test --env=jsdom", - "eject": "react-scripts eject" + "eject": "react-scripts eject", + "deploy": "npm run build && cpx \"build/**\" gh-pages/nested-reused-components && gh-pages -d gh-pages -r https://github.com/MrEfrem/mrefrem.github.io.git -b master -v nested-reused-components && rimraf gh-pages" } } diff --git a/examples/nested_reused_components/src/index.js b/examples/nested_reused_components/src/index.js index be357c9..eab2e91 100644 --- a/examples/nested_reused_components/src/index.js +++ b/examples/nested_reused_components/src/index.js @@ -7,10 +7,9 @@ import { enhanceStore } from 'redux-fly' import Layout from './containers/page/Layout' const composeEnhancers = - process.env.NODE_ENV !== 'production' && - typeof window === 'object' && - window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? - window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({}) : compose + typeof window === 'object' && + window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? + window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({}) : compose const store = createStore(null, composeEnhancers(enhanceStore)) const target = document.getElementById('root') diff --git a/examples/reused_components/package.json b/examples/reused_components/package.json index 0049266..a8bc1bc 100644 --- a/examples/reused_components/package.json +++ b/examples/reused_components/package.json @@ -2,10 +2,14 @@ "name": "reused_components", "version": "0.1.0", "private": true, + "homepage": "https://mrefrem.github.io/reused-components", "devDependencies": { + "cpx": "^1.5.0", "enzyme": "^2.6.0", + "gh-pages": "^0.12.0", "react-addons-test-utils": "^15.3.2", - "react-scripts": "0.7.0" + "react-scripts": "0.7.0", + "rimraf": "^2.5.4" }, "dependencies": { "react": "^15.3.2", @@ -20,6 +24,7 @@ "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test --env=jsdom", - "eject": "react-scripts eject" + "eject": "react-scripts eject", + "deploy": "npm run build && cpx \"build/**\" gh-pages/reused-components && gh-pages -d gh-pages -r https://github.com/MrEfrem/mrefrem.github.io.git -b master -v reused-components && rimraf gh-pages" } } diff --git a/examples/reused_components/src/index.js b/examples/reused_components/src/index.js index be357c9..eab2e91 100644 --- a/examples/reused_components/src/index.js +++ b/examples/reused_components/src/index.js @@ -7,10 +7,9 @@ import { enhanceStore } from 'redux-fly' import Layout from './containers/page/Layout' const composeEnhancers = - process.env.NODE_ENV !== 'production' && - typeof window === 'object' && - window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? - window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({}) : compose + typeof window === 'object' && + window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? + window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({}) : compose const store = createStore(null, composeEnhancers(enhanceStore)) const target = document.getElementById('root') diff --git a/examples/universal/package.json b/examples/universal/package.json index cd4bc88..a64758b 100644 --- a/examples/universal/package.json +++ b/examples/universal/package.json @@ -26,7 +26,7 @@ "react-redux": "^4.4.5", "redbox-react": "^1.3.3", "redux": "^3.5.2", - "redux-fly": "^0.0.1-alpha.3", + "redux-fly": "*", "serialize-javascript": "^1.2.0", "webpack": "^1.13.0", "webpack-hot-middleware": "^2.9.1" diff --git a/package.json b/package.json index 17809ec..d3362f2 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "eslint": "^3.5.0", "eslint-plugin-import": "^2.2.0", "eslint-plugin-react": "^6.3.0", + "flow-bin": "^0.36.0", "jest-cli": "^17.0.0", "react": "^15.4.0", "react-addons-test-utils": "^15.4.0", @@ -70,8 +71,8 @@ }, "peerDependencies": { "react": "15.x", - "redux": "3.x", - "react-redux": "4.x" + "react-redux": "4.x", + "redux": "3.x" }, "jest": { "testPathIgnorePatterns": [