Skip to content

Commit

Permalink
feat: warn user if defaultCommit or defaultRollback are not proper re…
Browse files Browse the repository at this point in the history
…dux actions
  • Loading branch information
sebasgarcep committed Sep 25, 2017
1 parent 6ff6b29 commit 661d542
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ import { applyDefaults } from './config';
import { networkStatusChanged } from './actions';

// @TODO: Take createStore as config?
const warnIfNotReduxAction = (config: $Shape<Config>, key: string) => {
const maybeAction = config[key];

const isNotReduxAction =
maybeAction === null ||
typeof maybeAction !== 'object' ||
typeof maybeAction.type !== 'string' ||
maybeAction.type === '';

if (isNotReduxAction && console.warn) {
const msg =
`${key} must be a proper redux action, ` +
`i.e. it must be an object and have a non-empty string type. ` +
`Instead you provided: ${JSON.stringify(maybeAction, null, 2)}`;
console.warn(msg);
}
};

// eslint-disable-next-line no-unused-vars
let persistor;
Expand All @@ -18,6 +35,9 @@ export const offline = (userConfig: $Shape<Config> = {}) => (
) => (reducer: any, preloadedState: any, enhancer: any = x => x) => {
const config = applyDefaults(userConfig);

warnIfNotReduxAction(config, 'defaultCommit');
warnIfNotReduxAction(config, 'defaultRollback');

// wraps userland reducer with a top-level
// reducer that handles offline state updating
const offlineReducer = enhanceReducer(reducer);
Expand Down

0 comments on commit 661d542

Please sign in to comment.