Tweak to removeAtIndex interface

This commit is contained in:
Kai Moseley 2017-01-24 16:25:11 +00:00
parent 1cd4cbf6bf
commit de67a74ac3
2 changed files with 4 additions and 4 deletions

View File

@ -40,7 +40,7 @@ describe('arrayReducer', () => {
describe('removeAtIndex', () => {
const { removeAtIndex } = DEFAULT_ARRAY_BEHAVIORS;
it('should remove at index correctly', () => {
expect(removeAtIndex.reducer([1,2,3], undefined, undefined, 0)).toEqual([2,3]);
expect(removeAtIndex.reducer([1,2,3], 0)).toEqual([2,3]);
});
it('should return state if no index provided', () => {
expect(removeAtIndex.reducer([1,2,3])).toEqual([1,2,3]);

View File

@ -45,7 +45,7 @@ import { updateAtIndex, removeAtIndex } from '../utils/arrayUtils';
import { PROP_TYPES } from '../structure';
function checkIndex(index: ?number, payload: any, behaviorName: string): boolean {
function checkIndex(index: ?number, payload: any = '', behaviorName: string = ''): boolean {
if (!isNumber(index) || index === -1) {
console.warn(`Index not passed to ${behaviorName} for payload ${payload}.`);
return false;
@ -81,8 +81,8 @@ export const DEFAULT_ARRAY_BEHAVIORS: ArrayReducerBehaviorsConfig = {
validate: false,
},
removeAtIndex: {
reducer(state, payload, initialState, index) {
if (!checkIndex(index, payload, 'removeAtIndex')) return state;
reducer(state, index) {
if (!checkIndex(index, '', 'removeAtIndex')) return state;
return removeAtIndex(state, index);
},
validate: false,