Skip to content

Commit

Permalink
code style
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc committed Oct 9, 2016
1 parent bb449e5 commit 6fb6fa6
Showing 1 changed file with 40 additions and 10 deletions.
50 changes: 40 additions & 10 deletions src/createDva.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ export default function createDva(createOpts) {

// extra reducers
const extraReducers = plugin.get('extraReducers');
invariant(Object.keys(extraReducers).every(key => !(key in reducers)), 'app.start: extraReducers is conflict with other reducers');
invariant(
Object.keys(extraReducers).every(key => !(key in reducers)),
'app.start: extraReducers is conflict with other reducers'
);

// create store
const extraMiddlewares = plugin.get('onAction');
Expand Down Expand Up @@ -197,17 +200,38 @@ export default function createDva(createOpts) {
const model = { ...m };
const { namespace, reducers, effects } = model;

invariant(namespace, 'app.model: namespace should be defined');
invariant(mobile || namespace !== 'routing', 'app.model: namespace should not be routing, it\'s used by react-redux-router');
invariant(!model.subscriptions || isPlainObject(model.subscriptions), 'app.model: subscriptions should be Object');
invariant(!reducers || isPlainObject(reducers) || Array.isArray(reducers), 'app.model: reducers should be Object or array');
invariant(!Array.isArray(reducers) || (isPlainObject(reducers[0]) && typeof reducers[1] === 'function'), 'app.model: reducers with array should be app.model({ reducers: [object, function] })')
invariant(!effects || isPlainObject(effects), 'app.model: effects should be Object');
invariant(
namespace,
'app.model: namespace should be defined'
);
invariant(
mobile || namespace !== 'routing',
'app.model: namespace should not be routing, it\'s used by react-redux-router'
);
invariant(
!model.subscriptions || isPlainObject(model.subscriptions),
'app.model: subscriptions should be Object'
);
invariant(
!reducers || isPlainObject(reducers) || Array.isArray(reducers),
'app.model: reducers should be Object or array'
);
invariant(
!Array.isArray(reducers) || (isPlainObject(reducers[0]) && typeof reducers[1] === 'function'),
'app.model: reducers with array should be app.model({ reducers: [object, function] })'
);
invariant(
!effects || isPlainObject(effects),
'app.model: effects should be Object'
);

function applyNamespace(type) {
function getNamespacedReducers(reducers) {
return Object.keys(reducers).reduce((memo, key) => {
warning(key.indexOf(`${namespace}${SEP}`) !== 0, `app.model: ${type.slice(0, -1)} ${key} should not be prefixed with namespace ${namespace}`);
warning(
key.indexOf(`${namespace}${SEP}`) !== 0,
`app.model: ${type.slice(0, -1)} ${key} should not be prefixed with namespace ${namespace}`
);
memo[`${namespace}${SEP}${key}`] = reducers[key];
return memo;
}, {});
Expand Down Expand Up @@ -327,7 +351,10 @@ export default function createDva(createOpts) {
function put(action) {
const { type } = action;
invariant(type, 'dispatch: action should be a plain Object with type');
warning(type.indexOf(`${model.namespace}${SEP}`) !== 0, `effects.put: ${type} should not be prefixed with namespace ${model.namespace}`);
warning(
type.indexOf(`${model.namespace}${SEP}`) !== 0,
`effects.put: ${type} should not be prefixed with namespace ${model.namespace}`
);
return sagaEffects.put({ ...action, type: prefixType(type, model) });
}
return { ...sagaEffects, put };
Expand All @@ -337,7 +364,10 @@ export default function createDva(createOpts) {
return action => {
const { type } = action;
invariant(type, 'dispatch: action should be a plain Object with type');
warning(type.indexOf(`${model.namespace}${SEP}`) !== 0, `dispatch: ${type} should not be prefixed with namespace ${model.namespace}`);
warning(
type.indexOf(`${model.namespace}${SEP}`) !== 0,
`dispatch: ${type} should not be prefixed with namespace ${model.namespace}`
);
return dispatch({ ...action, type: prefixType(type, model) });
};
}
Expand Down

0 comments on commit 6fb6fa6

Please sign in to comment.