Skip to content

Commit

Permalink
Merge pull request #9 from pofigizm/next
Browse files Browse the repository at this point in the history
Next
  • Loading branch information
pofigizm authored Feb 24, 2019
2 parents b686436 + a30a185 commit 34665db
Show file tree
Hide file tree
Showing 16 changed files with 355 additions and 122 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
## 0.1.0 (2017-10-13)
## 1.0.0
* release
47 changes: 33 additions & 14 deletions example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"react-loadable": "5.5.0",
"react-redux": "5.0.7",
"react-scripts": "2.0.4",
"redux-dynamic": "0.2.3"
"redux-dynamic": "1.0.0"
},
"scripts": {
"start": "react-scripts start",
Expand Down
9 changes: 0 additions & 9 deletions example/src/App.test.js

This file was deleted.

12 changes: 6 additions & 6 deletions example/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { createInstance } from 'redux-dynamic'
import Loadable from 'react-loadable';
import * as moduleOne from './module-one';

const dynamicStore = createInstance();
const dynamicStore = createInstance({ key: 'base' });
const store = dynamicStore.getStore();

// sync module
Expand All @@ -19,15 +19,15 @@ store.dispatch(moduleOne.actions.init());

// async module
const ModuleTwoContainer = Loadable({
loader: () => import('./module-two'),
loading: () => <div> module-two loading... </div>,
render: (loaded, props) => {
loader: () => import('./module-two')
.then((loaded) => {
const { Container, ...moduleTwo} = loaded;
dynamicStore.attach(moduleTwo);
store.dispatch(moduleTwo.actions.init());

return <Container {...props} />;
}
return Container;
}),
loading: () => <div> module-two loading... </div>
});

ReactDOM.render(
Expand Down
4 changes: 2 additions & 2 deletions example/src/module-one/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ const change = (payload = {}) => {
};
};

export const init = (props) => async (dispatch, getState, { requestOneApi }) => {
export const init = (props) => async (dispatch, getState, { moduleOne }) => {
await dispatch(change(props));
await requestOneApi();
await moduleOne.requestApi();

return dispatch({ type: INIT });
};
13 changes: 6 additions & 7 deletions example/src/module-one/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@ import middleware from './middleware';
import reducer from './reducer';
import Container from './container';

const reducers = {
[constants.STORE_KEY]: reducer
const thunk = {
requestApi: () => new Promise(res => setTimeout(res, 2000))
};

const thunkConfig = {
requestOneApi: () => new Promise(res => setTimeout(res, 2000))
};
const key = constants.STORE_KEY;

export {
key,
actions,
constants,
middleware,
reducers,
reducer,
selectors,
thunkConfig,
thunk,
Container
};
4 changes: 2 additions & 2 deletions example/src/module-two/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ const change = (payload = {}) => {
};
};

export const init = (props) => async (dispatch, getState, { requestTwoApi }) => {
export const init = (props) => async (dispatch, getState, { moduleTwo }) => {
await dispatch(change(props));
await requestTwoApi();
await moduleTwo.requestApi();

return dispatch({ type: INIT });
};
25 changes: 11 additions & 14 deletions example/src/module-two/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,25 @@ import middleware from './middleware';
import reducer, { initialState as state } from './reducer';
import Container from './container';

const reducers = {
[constants.STORE_KEY]: reducer
};

const initialState = {
[constants.STORE_KEY]: {
...state,
someParam: true
}
const initial = {
...state,
someParam: true
}

const thunkConfig = {
requestTwoApi: () => new Promise(res => setTimeout(res, 2000))
const thunk = {
requestApi: () => new Promise(res => setTimeout(res, 2000))
};

const key = constants.STORE_KEY

export {
initialState,
key,
initial,
actions,
constants,
middleware,
reducers,
reducer,
selectors,
thunkConfig,
thunk,
Container
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "redux-dynamic",
"version": "0.2.5",
"version": "1.0.0",
"description": "Allow add or remove redux modules dynamically",
"main": "lib/index.js",
"scripts": {
Expand Down Expand Up @@ -33,7 +33,7 @@
"babel-core": "6.26.3",
"babel-jest": "23.6.0",
"babel-preset-pofigizm": "1.0.0",
"eslint": "5.7.0",
"eslint": "5.14.1",
"eslint-config-pofigizm": "1.0.0",
"jest": "23.6.0"
},
Expand Down
10 changes: 5 additions & 5 deletions src/configure-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import { createStore, applyMiddleware, compose } from 'redux'

const devEnv = process && process.env && process.env.NODE_ENV !== 'production'
const configureStore = ({
name = 'redux-dynamic',
withDevTools = true,
initialState,
rootReducer,
name,
withDevTools,
initial,
reducer,
dynamicMiddlewares,
}) => {
const middlewares = applyMiddleware(dynamicMiddlewares)
// eslint-disable-next-line no-underscore-dangle
const devTools = withDevTools && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
const composeEnhancers = devEnv && devTools ? devTools({ name }) : compose
const enhancers = composeEnhancers(middlewares)
const store = createStore(rootReducer, initialState, enhancers)
const store = createStore(reducer, initial, enhancers)

return store
}
Expand Down
Loading

0 comments on commit 34665db

Please sign in to comment.