Skip to content

Commit

Permalink
remove deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
bdwain committed Apr 27, 2019
1 parent 7e4d46d commit becd636
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 164 deletions.
30 changes: 0 additions & 30 deletions src/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,34 +294,6 @@ function list(cmds, options = {}) {
});
}

function batch(cmds) {
if (process.env.NODE_ENV !== 'production') {
throwInvariant(
Array.isArray(cmds) && cmds.every(isCmd),
'Cmd.batch: first and only argument to Cmd.batch must be an array of other Cmds'
);
}

console.warn(
'Cmd.batch is deprecated and will be removed in version 5. Please use Cmd.list (https://github.com/redux-loop/redux-loop/blob/master/docs/api-docs/cmds.md#cmdlistcmds-options)'
);
return list(cmds, { batch: true, sequence: false });
}

function sequence(cmds) {
if (process.env.NODE_ENV !== 'production') {
throwInvariant(
Array.isArray(cmds) && cmds.every(isCmd),
'Cmd.sequence: first and only argument to Cmd.sequence must be an array of other Cmds'
);
}

console.warn(
'Cmd.sequence is deprecated and will be removed in version 5. Please use Cmd.list (https://github.com/redux-loop/redux-loop/blob/master/docs/api-docs/cmds.md#cmdlistcmds-options)'
);
return list(cmds, { batch: true, sequence: true });
}

function simulateMap(simulation) {
let result = this.nestedCmd.simulate(simulation);
if (Array.isArray(result)) {
Expand Down Expand Up @@ -366,8 +338,6 @@ export default {
run,
action,
list,
batch,
sequence,
map,
none,
dispatch: dispatchSymbol,
Expand Down
56 changes: 4 additions & 52 deletions src/combine-reducers.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,7 @@
import { loop, isLoop, getCmd, getModel } from './loop';
import Cmd from './cmd';
import mergeChildReducers from './merge-child-reducers';

const defaultAccessor = (state, key) => {
return state[key];
};

const defaultMutator = (state, key, value) => {
return {
...state,
[key]: value
};
};

//TODO: change to be implemented using mergeChildReducers in 5.0
// export default function combineReducers(childMap){
// return (rootState = {}, action, ...args) => {
// return mergeChildReducers(rootState, action, childMap, ...args);
// };
// }

export default function(reducerMap, rootState, accessor, mutator) {
if (accessor || mutator || rootState) {
console.warn(`Passing customization parameters to combineReducers is deprecated. They will be removed in 5.0.
Integrations with popular libraries are being broken out into separate libraries.
Please see https://github.com/redux-loop/redux-loop/releases/tag/v4.2.0 for more details.`);
}
rootState = rootState || {};
accessor = accessor || defaultAccessor;
mutator = mutator || defaultMutator;

return (state = rootState, action, ...args) => {
let hasChanged = false;
let cmds = [];

const model = Object.keys(reducerMap).reduce((model, key) => {
const reducer = reducerMap[key];
const previousStateForKey = accessor(state, key);
let nextStateForKey = reducer(previousStateForKey, action, ...args);

if (isLoop(nextStateForKey)) {
cmds.push(getCmd(nextStateForKey));
nextStateForKey = getModel(nextStateForKey);
}

hasChanged = hasChanged || nextStateForKey !== previousStateForKey;
return mutator(model, key, nextStateForKey);
}, state);

return loop(
hasChanged ? model : state,
Cmd.list(cmds, { batch: true }) //todo: remove batch in 5.0
);
export default function combineReducers(childMap){
return (rootState = {}, action, ...args) => {
return mergeChildReducers(rootState, action, childMap, ...args);
};
}
40 changes: 0 additions & 40 deletions test/cmd.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -770,44 +770,4 @@ describe('Cmds', () => {
);
});
});

describe('Cmd.batch', () => {
let warn;
beforeEach(() => {
warn = jest.spyOn(console, 'warn').mockImplementation(() => {});
});

afterEach(() => {
warn.mockRestore();
});

it('creates a list with batch set to true and sequence set to false', async () => {
let cmd1 = Cmd.run(sideEffect),
cmd2 = Cmd.run(sideEffect);
let batch = Cmd.batch([cmd1, cmd2]);
expect(batch).toEqual(
Cmd.list([cmd1, cmd2], { batch: true, sequence: false })
);
});
});

describe('Cmd.sequence', () => {
let warn;
beforeEach(() => {
warn = jest.spyOn(console, 'warn').mockImplementation(() => {});
});

afterEach(() => {
warn.mockRestore();
});

it('creates a list with batch set to true and sequence set to true', async () => {
let cmd1 = Cmd.run(sideEffect),
cmd2 = Cmd.run(sideEffect);
let batch = Cmd.sequence([cmd1, cmd2]);
expect(batch).toEqual(
Cmd.list([cmd1, cmd2], { batch: true, sequence: true })
);
});
});
});
39 changes: 0 additions & 39 deletions test/combine-reducers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,43 +54,4 @@ describe('combineReducers', () => {
state = getModel(appReducer(state, {}, 1, 2));
expect(state).toEqual({ r1: [5, 6, 1, 2], r2: 6 });
});

it('works with custom data structure and returns correctly working reducer', () => {
let warn = jest.spyOn(console, 'warn').mockImplementation(() => {});
const appReducer = combineReducers(
reducers,
Map(),
(child, key) => child.get(key),
(child, key, value) => child.set(key, value)
);

expect(typeof appReducer).toBe('function');

let state = getModel(appReducer());
expect(state.toJS()).toEqual({ counter: 1, doubler: 1, fibonacci: 1 });

let action = {
type: 'NEXT FIBONACCI NUMBER',
previous: 0
};
state = getModel(appReducer(state, action));
expect(state.toJS()).toEqual({ counter: 2, doubler: 2, fibonacci: 1 });

action.previous = 1;
state = getModel(appReducer(state, action));
expect(state.toJS()).toEqual({ counter: 3, doubler: 4, fibonacci: 2 });

state = getModel(appReducer(state));
expect(state.toJS()).toEqual({ counter: 4, doubler: 8, fibonacci: 2 });

action.previous = 1;
state = getModel(appReducer(state, action));
expect(state.toJS()).toEqual({ counter: 5, doubler: 16, fibonacci: 3 });

action.previous = 2;
state = getModel(appReducer(state, action));
expect(state.toJS()).toEqual({ counter: 6, doubler: 32, fibonacci: 5 });

warn.mockRestore();
});
});
6 changes: 3 additions & 3 deletions test/reduce-reducers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe('reduceReducers', function() {
};
const cmd = Cmd.list([
Cmd.list([divideCmd, sideEffectCmd]),
Cmd.list([addCmd, multCmd], { batch: true })
Cmd.list([addCmd, multCmd])
]);
expect(reducer(initialState, action)).toEqual(loop(newState, cmd));
});
Expand All @@ -130,7 +130,7 @@ describe('reduceReducers', function() {
mult: 27
};
const cmd = Cmd.list([
Cmd.list([addCmd, multCmd], { batch: true }),
Cmd.list([addCmd, multCmd]),
Cmd.list([divideCmd, sideEffectCmd])
]);
expect(reducer(initialState, action)).toEqual(loop(newState, cmd));
Expand All @@ -144,7 +144,7 @@ describe('reduceReducers', function() {
};
const cmd = Cmd.list([
Cmd.list([divideCmd, sideEffectCmd]),
Cmd.list([addCmd, multCmd], { batch: true }),
Cmd.list([addCmd, multCmd]),
Cmd.list([divideCmd, sideEffectCmd])
]);
expect(reducer(initialState, action)).toEqual(loop(newState, cmd));
Expand Down

0 comments on commit becd636

Please sign in to comment.