Skip to content

Commit

Permalink
enhance: Simplify NM existance check in dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Mar 22, 2020
1 parent 36d45ce commit 47afd8d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 0 additions & 2 deletions packages/rest-hooks/src/state/NetworkManager.ts
Expand Up @@ -51,8 +51,6 @@ export default class NetworkManager implements Manager {
// It's important to intercept other fetches as we don't want to trigger reducers during
// render - so we need to stop 'readonly' fetches which can be triggered in render
if (action.meta.optimisticResponse !== undefined) {
/* istanbul ignore next */
if (process.env.NODE_ENV !== 'production') action.meta.nm = true;
return next(action);
}
return Promise.resolve();
Expand Down
22 changes: 12 additions & 10 deletions packages/rest-hooks/src/state/reducer.ts
Expand Up @@ -28,18 +28,20 @@ export default function reducer(
if (!state) state = initialState;
switch (action.type) {
case FETCH_TYPE: {
// If 'fetch' action reaches the reducer there are no middlewares installed to handle it
if (process.env.NODE_ENV !== 'production' && !action.meta.nm) {
console.warn(
'Fetch appears unhandled - you are likely missing the NetworkManager middleware',
);
console.warn(
'See https://resthooks.io/docs/guides/redux#indextsx for hooking up redux',
);
const optimisticResponse = action.meta.optimisticResponse;
if (optimisticResponse === undefined) {
// If 'fetch' action reaches the reducer there are no middlewares installed to handle it
if (process.env.NODE_ENV !== 'production') {
console.warn(
'Fetch appears unhandled - you are likely missing the NetworkManager middleware',
);
console.warn(
'See https://resthooks.io/docs/guides/redux#indextsx for hooking up redux',
);
}
return state;
}

const optimisticResponse = action.meta.optimisticResponse;
if (optimisticResponse === undefined) return state;
return {
...state,
optimistic: [
Expand Down

0 comments on commit 47afd8d

Please sign in to comment.