Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

redux-form

Package Overview
Dependencies
Maintainers
1
Versions
236
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-form - npm Package Compare versions

Comparing version 6.0.0-rc.4 to 6.0.0-rc.5

es/__tests__/Fields.spec.js

15

es/__tests__/actions.spec.js

@@ -219,3 +219,4 @@ import expect from 'expect';

meta: {
form: 'myForm'
form: 'myForm',
keepDirty: undefined
},

@@ -226,2 +227,14 @@ payload: data

it('should create initialize action with a keepDirty value', function () {
var data = { a: 8, c: 9 };
expect(initialize('myForm', data, true)).toEqual({
type: INITIALIZE,
meta: {
form: 'myForm',
keepDirty: true
},
payload: data
}).toPass(isFSA);
});
it('should create registerField action', function () {

@@ -228,0 +241,0 @@ expect(registerField('myForm', 'foo', 'Field')).toEqual({

@@ -0,1 +1,5 @@

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
import { createSpy } from 'expect';

@@ -215,2 +219,40 @@ import createFieldArrayProps from '../createFieldArrayProps';

it('should provide reduce', function () {
var callback = createSpy(function (accumulator, name) {
return _extends({}, accumulator, _defineProperty({}, name, { whatever: true, name: name }));
}).andCallThrough();
var result = createFieldArrayProps.apply(undefined, defaultProps.concat([{
value: fromJS(['a', 'b', 'c'])
}]));
expect(result.fields.reduce).toBeA('function');
expect(callback).toNotHaveBeenCalled();
var reduceResult = result.fields.reduce(callback, {});
expect(size(reduceResult), 3);
expect(reduceResult['foo[0]']).toEqual({ whatever: true, name: 'foo[0]' });
expect(reduceResult['foo[1]']).toEqual({ whatever: true, name: 'foo[1]' });
expect(reduceResult['foo[2]']).toEqual({ whatever: true, name: 'foo[2]' });
expect(callback).toHaveBeenCalled();
expect(callback.calls.length).toBe(3);
expect(callback.calls[0].arguments).toEqual([{}, 'foo[0]', 0]);
expect(callback.calls[1].arguments).toEqual([{
'foo[0]': { whatever: true, name: 'foo[0]' }
}, 'foo[1]', 1]);
expect(callback.calls[2].arguments).toEqual([{
'foo[0]': { whatever: true, name: 'foo[0]' },
'foo[1]': { whatever: true, name: 'foo[1]' }
}, 'foo[2]', 2]);
});
it('should provide reduce when no value', function () {
var callback = createSpy(function (accumulator, name) {
return _extends({}, accumulator, _defineProperty({}, name, { whatever: true, name: name }));
}).andCallThrough();
var result = createFieldArrayProps.apply(undefined, defaultProps.concat([{}]));
expect(result.fields.reduce).toBeA('function');
expect(callback).toNotHaveBeenCalled();
var reduceResult = result.fields.reduce(callback, {});
expect(size(reduceResult), 0);
expect(callback).toNotHaveBeenCalled();
});
it('should provide swap', function () {

@@ -227,2 +269,9 @@ var arraySwap = createSpy();

});
it('should provide a _isFieldArray meta prop', function () {
var result = createFieldArrayProps.apply(undefined, defaultProps.concat([{
value: fromJS(['a', 'b', 'c'])
}]));
expect(result.fields._isFieldArray).toBe(true);
});
});

@@ -229,0 +278,0 @@ };

35

es/__tests__/createFieldProps.spec.js

@@ -29,12 +29,15 @@ import { createSpy } from 'expect';

var blur = createSpy();
var normalize = createSpy(function (value) {
var dispatch = createSpy();
var normalize = createSpy(function (name, value) {
return value;
}).andCallThrough();
expect(blur).toNotHaveBeenCalled();
var result = createFieldProps(getIn, 'foo', { value: 'bar', blur: blur, normalize: normalize });
var result = createFieldProps(getIn, 'foo', { value: 'bar', blur: blur, dispatch: dispatch, normalize: normalize });
expect(result.input.onBlur).toBeA('function');
expect(blur).toNotHaveBeenCalled();
expect(dispatch).toNotHaveBeenCalled();
result.input.onBlur('rabbit');
expect(normalize).toHaveBeenCalled();
expect(blur).toHaveBeenCalled().toHaveBeenCalledWith('rabbit');
expect(blur).toHaveBeenCalled().toHaveBeenCalledWith('foo', 'rabbit');
expect(dispatch).toHaveBeenCalled();
});

@@ -44,12 +47,15 @@

var change = createSpy();
var normalize = createSpy(function (value) {
var dispatch = createSpy();
var normalize = createSpy(function (name, value) {
return value;
}).andCallThrough();
expect(change).toNotHaveBeenCalled();
var result = createFieldProps(getIn, 'foo', { value: 'bar', change: change, normalize: normalize });
var result = createFieldProps(getIn, 'foo', { value: 'bar', change: change, dispatch: dispatch, normalize: normalize });
expect(result.input.onChange).toBeA('function');
expect(change).toNotHaveBeenCalled();
expect(dispatch).toNotHaveBeenCalled();
result.input.onChange('rabbit');
expect(normalize).toHaveBeenCalled();
expect(change).toHaveBeenCalled().toHaveBeenCalledWith('rabbit');
expect(change).toHaveBeenCalled().toHaveBeenCalledWith('foo', 'rabbit');
expect(dispatch).toHaveBeenCalled();
});

@@ -59,8 +65,11 @@

var focus = createSpy();
var dispatch = createSpy();
expect(focus).toNotHaveBeenCalled();
var result = createFieldProps(getIn, 'foo', { value: 'bar', focus: focus });
var result = createFieldProps(getIn, 'foo', { value: 'bar', dispatch: dispatch, focus: focus });
expect(result.input.onFocus).toBeA('function');
expect(focus).toNotHaveBeenCalled();
expect(dispatch).toNotHaveBeenCalled();
result.input.onFocus('rabbit');
expect(focus).toHaveBeenCalled().toHaveBeenCalledWith('foo');
expect(dispatch).toHaveBeenCalled();
});

@@ -93,2 +102,14 @@

it('should pass along submitting flag', function () {
var notSubmittingResult = createFieldProps(getIn, 'foo', {
value: 'bar'
});
expect(notSubmittingResult.meta.submitting).toBe(false);
var submittingResult = createFieldProps(getIn, 'foo', {
value: 'bar',
submitting: true
});
expect(submittingResult.meta.submitting).toBe(true);
});
it('should read touched from state', function () {

@@ -95,0 +116,0 @@ var untouchedResult = createFieldProps(getIn, 'foo', {

@@ -141,2 +141,25 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

it('should allow an empty value from Redux state to be pristine', function () {
var props1 = testProps({
initial: {
foo: 'bar'
},
values: {
foo: ''
}
});
expect(props1.meta.pristine).toBe(false);
expect(props1.meta.dirty).toBe(true);
var props2 = testProps({
initial: {
foo: ''
},
values: {
foo: ''
}
});
expect(props2.meta.pristine).toBe(true);
expect(props2.meta.dirty).toBe(false);
});
it('should get asyncValidating from Redux state', function () {

@@ -679,7 +702,4 @@ var props1 = testProps({

it('should rerender when props change', function () {
it('should re-register when name changes', function () {
var store = makeStore();
var input = createSpy(function (props) {
return React.createElement('input', props.input);
}).andCallThrough();

@@ -694,3 +714,3 @@ var Form = function (_Component13) {

_this14.state = { foo: 'foo' };
_this14.state = { field: 'foo' };
return _this14;

@@ -707,2 +727,70 @@ }

null,
React.createElement(Field, { name: this.state.field, component: 'input' }),
React.createElement(
'button',
{ onClick: function onClick() {
return _this15.setState({ field: 'bar' });
} },
'Change'
)
);
}
}]);
return Form;
}(Component);
var TestForm = reduxForm({ form: 'testForm' })(Form);
var dom = TestUtils.renderIntoDocument(React.createElement(
Provider,
{ store: store },
React.createElement(TestForm, null)
));
expect(store.getState()).toEqualMap({
form: {
testForm: {
registeredFields: [{ name: 'foo', type: 'Field' }]
}
}
});
var button = TestUtils.findRenderedDOMComponentWithTag(dom, 'button');
TestUtils.Simulate.click(button);
expect(store.getState()).toEqualMap({
form: {
testForm: {
registeredFields: [{ name: 'bar', type: 'Field' }]
}
}
});
});
it('should rerender when props change', function () {
var store = makeStore();
var input = createSpy(function (props) {
return React.createElement('input', props.input);
}).andCallThrough();
var Form = function (_Component14) {
_inherits(Form, _Component14);
function Form() {
_classCallCheck(this, Form);
var _this16 = _possibleConstructorReturn(this, Object.getPrototypeOf(Form).call(this));
_this16.state = { foo: 'foo' };
return _this16;
}
_createClass(Form, [{
key: 'render',
value: function render() {
var _this17 = this;
return React.createElement(
'div',
null,
React.createElement(Field, { name: 'foo', rel: this.state.foo, component: input }),

@@ -712,3 +800,3 @@ React.createElement(

{ onClick: function onClick() {
return _this15.setState({ foo: 'qux' });
return _this17.setState({ foo: 'qux' });
} },

@@ -748,4 +836,4 @@ 'Change'

var Form = function (_Component14) {
_inherits(Form, _Component14);
var Form = function (_Component15) {
_inherits(Form, _Component15);

@@ -755,6 +843,6 @@ function Form() {

var _this16 = _possibleConstructorReturn(this, Object.getPrototypeOf(Form).call(this));
var _this18 = _possibleConstructorReturn(this, Object.getPrototypeOf(Form).call(this));
_this16.state = { foo: 'bar' };
return _this16;
_this18.state = { foo: 'bar' };
return _this18;
}

@@ -765,3 +853,3 @@

value: function render() {
var _this17 = this;
var _this19 = this;

@@ -776,3 +864,3 @@ renderSpy();

{ onClick: function onClick() {
return _this17.setState({ foo: 'qux' });
return _this19.setState({ foo: 'qux' });
} },

@@ -826,4 +914,4 @@ 'Change'

var Form = function (_Component15) {
_inherits(Form, _Component15);
var Form = function (_Component16) {
_inherits(Form, _Component16);

@@ -895,4 +983,4 @@ function Form() {

var Form = function (_Component16) {
_inherits(Form, _Component16);
var Form = function (_Component17) {
_inherits(Form, _Component17);

@@ -962,4 +1050,4 @@ function Form() {

var Form = function (_Component17) {
_inherits(Form, _Component17);
var Form = function (_Component18) {
_inherits(Form, _Component18);

@@ -1015,4 +1103,4 @@ function Form() {

var Form = function (_Component18) {
_inherits(Form, _Component18);
var Form = function (_Component19) {
_inherits(Form, _Component19);

@@ -1076,4 +1164,4 @@ function Form() {

var Form = function (_Component19) {
_inherits(Form, _Component19);
var Form = function (_Component20) {
_inherits(Form, _Component20);

@@ -1140,4 +1228,4 @@ function Form() {

var Form = function (_Component20) {
_inherits(Form, _Component20);
var Form = function (_Component21) {
_inherits(Form, _Component21);

@@ -1233,4 +1321,4 @@ function Form() {

var Form = function (_Component21) {
_inherits(Form, _Component21);
var Form = function (_Component22) {
_inherits(Form, _Component22);

@@ -1300,4 +1388,4 @@ function Form() {

var Form = function (_Component22) {
_inherits(Form, _Component22);
var Form = function (_Component23) {
_inherits(Form, _Component23);

@@ -1304,0 +1392,0 @@ function Form() {

@@ -23,2 +23,3 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

import createField from '../Field';
import createFields from '../Fields';
import plain from '../structure/plain';

@@ -36,2 +37,3 @@ import plainExpectations from '../structure/plain/expectations';

var Field = createField(structure);
var Fields = createFields(structure);
var reducer = createReducer(structure);

@@ -1087,2 +1089,71 @@ var fromJS = structure.fromJS;

});
it('should work with Fields', function () {
var store = makeStore({
testForm: {
values: {
foo: ['firstValue', 'secondValue']
}
}
});
var renderField = createSpy(function (field) {
return React.createElement('input', field.input);
});
var renderFields = createSpy(function (_ref3) {
var foo = _ref3.foo;
return React.createElement(
'div',
null,
foo.map(renderField)
);
}).andCallThrough();
var component = createSpy(function (_ref4) {
var fields = _ref4.fields;
return React.createElement(
'div',
null,
React.createElement(Fields, { names: fields, component: renderFields })
);
}).andCallThrough();
var Form = function (_Component17) {
_inherits(Form, _Component17);
function Form() {
_classCallCheck(this, Form);
return _possibleConstructorReturn(this, Object.getPrototypeOf(Form).apply(this, arguments));
}
_createClass(Form, [{
key: 'render',
value: function render() {
return React.createElement(
'div',
null,
React.createElement(FieldArray, { name: 'foo', component: component })
);
}
}]);
return Form;
}(Component);
var TestForm = reduxForm({ form: 'testForm' })(Form);
TestUtils.renderIntoDocument(React.createElement(
Provider,
{ store: store },
React.createElement(TestForm, null)
));
expect(renderFields).toHaveBeenCalled();
expect(renderFields.calls.length).toBe(1);
expect(renderFields.calls[0].arguments[0].foo.length).toBe(2);
expect(renderField).toHaveBeenCalled();
expect(renderField.calls.length).toBe(2);
expect(renderField.calls[0].arguments[0].input.value).toBe('firstValue');
expect(renderField.calls[1].arguments[0].input.value).toBe('secondValue');
});
};

@@ -1089,0 +1160,0 @@

@@ -83,3 +83,3 @@ import _noop from 'lodash-es/noop';

it('should not submit if async validation fails', function (done) {
it('should not submit if async validation fails', function () {
var values = { foo: 'bar', baz: 42 };

@@ -105,7 +105,6 @@ var submit = createSpy().andReturn(69);

expect(setSubmitFailed).toHaveBeenCalled().toHaveBeenCalledWith('foo', 'baz');
done();
});
});
it('should not submit if async validation fails and return rejected promise', function (done) {
it('should not submit if async validation fails and return rejected promise', function () {
var values = { foo: 'bar', baz: 42 };

@@ -134,3 +133,2 @@ var submit = createSpy().andReturn(69);

expect(setSubmitFailed).toHaveBeenCalled().toHaveBeenCalledWith('foo', 'baz');
done();
});

@@ -187,3 +185,3 @@ });

it('should set submit errors if async submit fails', function (done) {
it('should set submit errors if async submit fails', function () {
var values = { foo: 'bar', baz: 42 };

@@ -210,7 +208,6 @@ var submitErrors = { foo: 'submit error' };

expect(setSubmitSucceeded).toNotHaveBeenCalled();
done();
});
});
it('should not set errors if rejected value not a SubmissionError', function (done) {
it('should not set errors if rejected value not a SubmissionError', function () {
var values = { foo: 'bar', baz: 42 };

@@ -237,7 +234,6 @@ var submitErrors = { foo: 'submit error' };

expect(setSubmitSucceeded).toNotHaveBeenCalled();
done();
});
});
it('should set submit errors if async submit fails and return rejected promise', function (done) {
it('should set submit errors if async submit fails and return rejected promise', function () {
var values = { foo: 'bar', baz: 42 };

@@ -266,5 +262,4 @@ var submitErrors = { foo: 'submit error' };

expect(setSubmitSucceeded).toNotHaveBeenCalled();
done();
});
});
});

@@ -112,2 +112,17 @@ import createHasError from '../hasError';

});
it('should return true if a Field that has an object value has an _error', function () {
var field = fromJS({ name: 'foo', type: 'Field' });
var plainError = {
foo: {
_error: 'An error'
}
};
expect(hasError(field, plainError)).toBe(true);
var error = fromJS(plainError);
expect(hasError(field, null, error)).toBe(true);
expect(hasError(field, null, null, error)).toBe(true);
});
});

@@ -114,0 +129,0 @@ };

@@ -155,2 +155,77 @@ import { initialize } from '../actions';

});
it('should retain dirty values when keepDirty is set', function () {
var state = reducer(fromJS({
foo: {
registeredFields: [{ name: 'myField', type: 'Field' }],
values: {
myField: 'dirtyValue'
},
initial: {
myField: 'initialValue'
}
}
}), initialize('foo', { myField: 'newValue' }, true));
expect(state).toEqualMap({
foo: {
registeredFields: [{ name: 'myField', type: 'Field' }],
values: {
myField: 'dirtyValue'
},
initial: {
myField: 'newValue'
}
}
});
});
it('should replace pristine values when keepDirty is set', function () {
var state = reducer(fromJS({
foo: {
registeredFields: [{ name: 'myField', type: 'Field' }],
values: {
myField: 'initialValue'
},
initial: {
myField: 'initialValue'
}
}
}), initialize('foo', { myField: 'newValue' }, true));
expect(state).toEqualMap({
foo: {
registeredFields: [{ name: 'myField', type: 'Field' }],
values: {
myField: 'newValue'
},
initial: {
myField: 'newValue'
}
}
});
});
it('should treat a matching dirty value as pristine when keepDirty is set', function () {
var state = reducer(fromJS({
foo: {
registeredFields: [{ name: 'myField', type: 'Field' }],
values: {
myField: 'newValue'
},
initial: {
myField: 'initialValue'
}
}
}), initialize('foo', { myField: 'newValue' }, true));
expect(state).toEqualMap({
foo: {
registeredFields: [{ name: 'myField', type: 'Field' }],
values: {
myField: 'newValue'
},
initial: {
myField: 'newValue'
}
}
});
});
};

@@ -157,0 +232,0 @@ };

@@ -24,2 +24,15 @@ import { unregisterField } from '../actions';

});
it('should do nothing if the field is not registered', function () {
var state = reducer(fromJS({
foo: {
registeredFields: [{ name: 'bar', type: 'field' }]
}
}), unregisterField('foo', 'baz'));
expect(state).toEqualMap({
foo: {
registeredFields: [{ name: 'bar', type: 'field' }]
}
});
});
};

@@ -26,0 +39,0 @@ };

@@ -32,2 +32,27 @@ import { updateSyncErrors } from '../actions';

it('should update form-wide error', function () {
var state = reducer(fromJS({
foo: {
values: {
myField: 'value',
myOtherField: 'otherValue'
}
}
}), updateSyncErrors('foo', {
myField: 'myField error',
_error: 'form wide error'
}));
expect(state).toEqualMap(setIn(fromJS({
foo: {
values: {
myField: 'value',
myOtherField: 'otherValue'
},
error: 'form wide error'
}
}), 'foo.syncErrors', {
myField: 'myField error'
}));
});
it('should update complex sync errors', function () {

@@ -34,0 +59,0 @@ var state = reducer(fromJS({

@@ -72,4 +72,4 @@ import { ARRAY_INSERT, ARRAY_MOVE, ARRAY_POP, ARRAY_PUSH, ARRAY_REMOVE, ARRAY_REMOVE_ALL, ARRAY_SHIFT, ARRAY_SPLICE, ARRAY_SWAP, ARRAY_UNSHIFT, BLUR, CHANGE, DESTROY, FOCUS, INITIALIZE, REGISTER_FIELD, RESET, SET_SUBMIT_FAILED, SET_SUBMIT_SUCCEEDED, START_ASYNC_VALIDATION, START_SUBMIT, STOP_ASYNC_VALIDATION, STOP_SUBMIT, TOUCH, UNREGISTER_FIELD, UNTOUCH, UPDATE_SYNC_ERRORS } from './actionTypes';

export var initialize = function initialize(form, values) {
return { type: INITIALIZE, meta: { form: form }, payload: values };
export var initialize = function initialize(form, values, keepDirty) {
return { type: INITIALIZE, meta: { form: form, keepDirty: keepDirty }, payload: values };
};

@@ -76,0 +76,0 @@

@@ -1,3 +0,1 @@

import _mapValues from 'lodash-es/mapValues';
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

@@ -18,3 +16,2 @@

import createFieldProps from './createFieldProps';
import plain from './structure/plain';

@@ -80,3 +77,7 @@

var props = createFieldProps(getIn, name, rest, asyncValidate);
var props = createFieldProps(getIn, name, _extends({}, rest, {
blur: blur,
change: change,
focus: focus
}), asyncValidate);
if (withRef) {

@@ -109,13 +110,8 @@ props.ref = 'renderedComponent';

var actions = _mapValues({
blur: blur,
change: change,
focus: focus
}, function (actionCreator) {
return actionCreator.bind(null, name);
});
var connector = connect(function (state, ownProps) {
var formState = getFormState(state);
var initial = getIn(formState, 'initial.' + name) || propInitialValue;
var initialState = getIn(formState, 'initial.' + name);
var initial = initialState === undefined ? propInitialValue : initialState;
var value = getIn(formState, 'values.' + name);
var submitting = getIn(formState, 'submitting');
var syncError = getSyncError(getIn(formState, 'syncErrors'));

@@ -130,2 +126,3 @@ var pristine = value === initial;

submitError: getIn(formState, 'submitErrors.' + name),
submitting: submitting,
syncError: syncError,

@@ -135,3 +132,3 @@ value: value,

};
}, actions, undefined, { withRef: true });
}, undefined, undefined, { withRef: true });
return connector(ConnectedField);

@@ -138,0 +135,0 @@ };

@@ -133,2 +133,3 @@ import _mapValues from 'lodash-es/mapValues';

var value = getIn(formState, 'values.' + name);
var submitting = getIn(formState, 'submitting');
var syncError = getSyncError(getIn(formState, 'syncErrors'));

@@ -141,2 +142,3 @@ var pristine = deepEqual(value, initial);

submitError: getIn(formState, 'submitErrors.' + name + '._error'),
submitting: submitting,
syncError: syncError,

@@ -143,0 +145,0 @@ value: value

@@ -6,2 +6,3 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

import createField from './Field';
import createFields from './Fields';
import createFieldArray from './FieldArray';

@@ -26,2 +27,3 @@ import createFormValueSelector from './formValueSelector';

Field: createField(structure),
Fields: createFields(structure),
FieldArray: createFieldArray(structure),

@@ -28,0 +30,0 @@ formValueSelector: createFormValueSelector(structure),

@@ -21,2 +21,3 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var submitFailed = _ref.submitFailed;
var submitting = _ref.submitting;
var syncError = _ref.syncError;

@@ -26,3 +27,3 @@ var value = _ref.value;

var rest = _objectWithoutProperties(_ref, ["arrayInsert", "arrayMove", "arrayPop", "arrayPush", "arrayRemove", "arrayRemoveAll", "arrayShift", "arraySplice", "arraySwap", "arrayUnshift", "asyncError", "dirty", "pristine", "submitError", "submitFailed", "syncError", "value", "props"]);
var rest = _objectWithoutProperties(_ref, ["arrayInsert", "arrayMove", "arrayPop", "arrayPush", "arrayRemove", "arrayRemoveAll", "arrayShift", "arraySplice", "arraySwap", "arrayUnshift", "asyncError", "dirty", "pristine", "submitError", "submitFailed", "submitting", "syncError", "value", "props"]);

@@ -33,2 +34,3 @@ var error = syncError || asyncError || submitError;

fields: {
_isFieldArray: true,
forEach: function forEach(callback) {

@@ -52,2 +54,7 @@ return (value || []).forEach(function (item, index) {

push: arrayPush,
reduce: function reduce(callback, initial) {
return (value || []).reduce(function (accumulator, item, index) {
return callback(accumulator, name + "[" + index + "]", index);
}, initial);
},
remove: arrayRemove,

@@ -67,2 +74,3 @@ removeAll: arrayRemoveAll,

pristine: pristine,
submitting: submitting,
valid: !error

@@ -69,0 +77,0 @@ }

@@ -49,2 +49,3 @@ import _noop from 'lodash-es/noop';

var dirty = _ref.dirty;
var dispatch = _ref.dispatch;
var focus = _ref.focus;

@@ -58,2 +59,3 @@ var format = _ref.format;

var submitError = _ref.submitError;
var submitting = _ref.submitting;
var value = _ref.value;

@@ -63,3 +65,3 @@ var _value = _ref._value;

var custom = _objectWithoutProperties(_ref, ['asyncError', 'asyncValidating', 'blur', 'change', 'defaultValue', 'dirty', 'focus', 'format', 'normalize', 'parse', 'pristine', 'props', 'state', 'submitError', 'value', '_value', 'syncError']);
var custom = _objectWithoutProperties(_ref, ['asyncError', 'asyncValidating', 'blur', 'change', 'defaultValue', 'dirty', 'dispatch', 'focus', 'format', 'normalize', 'parse', 'pristine', 'props', 'state', 'submitError', 'submitting', 'value', '_value', 'syncError']);

@@ -69,3 +71,12 @@ var asyncValidate = arguments.length <= 3 || arguments[3] === undefined ? _noop : arguments[3];

var error = syncError || asyncError || submitError;
var onChange = createOnChange(change, { normalize: normalize, parse: parse });
var boundNormalize = normalize && function (value) {
return normalize(name, value);
};
var boundChange = function boundChange(value) {
return dispatch(change(name, value));
};
var onChange = createOnChange(boundChange, {
normalize: boundNormalize,
parse: parse
});
var fieldValue = value == null ? defaultValue : value;

@@ -76,7 +87,15 @@

name: name,
onBlur: createOnBlur(blur, { normalize: normalize, parse: parse, after: asyncValidate.bind(null, name) }),
onBlur: createOnBlur(function (value) {
return dispatch(blur(name, value));
}, {
normalize: boundNormalize,
parse: parse,
after: asyncValidate.bind(null, name)
}),
onChange: onChange,
onDragStart: createOnDragStart(name, fieldValue),
onDrop: createOnDrop(name, change),
onFocus: createOnFocus(name, focus),
onDrop: createOnDrop(name, boundChange),
onFocus: createOnFocus(name, function () {
return dispatch(focus(name));
}),
value: format ? format(fieldValue) : fieldValue

@@ -91,2 +110,3 @@ }, _value),

pristine: pristine,
submitting: !!submitting,
touched: !!(state && getIn(state, 'touched')),

@@ -93,0 +113,0 @@ valid: !error,

@@ -56,2 +56,6 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

this.ConnectedField = createConnectedField(this.context._reduxForm, { deepEqual: deepEqual, getIn: getIn }, nextProps.name);
// unregister old name
this.context._reduxForm.unregister(this.props.name);
// register new name
this.context._reduxForm.register(nextProps.name, 'Field');
}

@@ -72,3 +76,3 @@ }

key: 'normalize',
value: function normalize(value) {
value: function normalize(name, value) {
var normalize = this.props.normalize;

@@ -81,3 +85,3 @@

var previousValue = this.value;
var nextValues = setIn(previousValues, this.props.name, value);
var nextValues = setIn(previousValues, name, value);
return normalize(value, previousValue, nextValues, previousValues);

@@ -84,0 +88,0 @@ }

import plainGetIn from './structure/plain/getIn';
var getErrorKey = function getErrorKey(name, type) {
var getErrorKeys = function getErrorKeys(name, type) {
switch (type) {
case 'Field':
return name;
return [name, name + '._error'];
case 'FieldArray':
return name + '._error';
return [name + '._error'];
}

@@ -21,13 +21,23 @@ };

}
var errorKey = getErrorKey(name, type);
var syncError = plainGetIn(syncErrors, errorKey);
if (syncError && typeof syncError === 'string') {
var errorKeys = getErrorKeys(name, type);
var syncError = errorKeys.reduce(function (error, errorKey) {
var curError = plainGetIn(syncErrors, errorKey);
return curError ? error + curError : error;
}, null);
if (syncError != null) {
return true;
}
var asyncError = getIn(asyncErrors, errorKey);
if (asyncError && typeof asyncError === 'string') {
var asyncError = errorKeys.reduce(function (error, errorKey) {
var curError = getIn(asyncErrors, errorKey);
return curError ? error + curError : error;
}, null);
if (asyncError != null) {
return true;
}
var submitError = getIn(submitErrors, errorKey);
if (submitError && typeof submitError === 'string') {
var submitError = errorKeys.reduce(function (error, errorKey) {
var curError = getIn(submitErrors, errorKey);
return curError ? error + curError : error;
}, null);
if (submitError != null) {
return true;

@@ -34,0 +44,0 @@ }

@@ -21,2 +21,3 @@ import createAll from './createAll';

var Field = _createAll.Field;
var Fields = _createAll.Fields;
var FieldArray = _createAll.FieldArray;

@@ -45,2 +46,2 @@ var focus = _createAll.focus;

var values = _createAll.values;
export { actionTypes, arrayInsert, arrayMove, arrayPop, arrayPush, arrayRemove, arrayRemoveAll, arrayShift, arraySplice, arraySwap, arrayUnshift, blur, change, destroy, Field, FieldArray, focus, formValueSelector, getFormValues, initialize, isDirty, isInvalid, isPristine, isValid, propTypes, reducer, reduxForm, reset, setSubmitFailed, setSubmitSucceeded, startAsyncValidation, startSubmit, stopAsyncValidation, stopSubmit, SubmissionError, touch, untouch, values };
export { actionTypes, arrayInsert, arrayMove, arrayPop, arrayPush, arrayRemove, arrayRemoveAll, arrayShift, arraySplice, arraySwap, arrayUnshift, blur, change, destroy, Field, Fields, FieldArray, focus, formValueSelector, getFormValues, initialize, isDirty, isInvalid, isPristine, isValid, propTypes, reducer, reduxForm, reset, setSubmitFailed, setSubmitSucceeded, startAsyncValidation, startSubmit, stopAsyncValidation, stopSubmit, SubmissionError, touch, untouch, values };

@@ -21,2 +21,3 @@ import createAll from './createAll';

var Field = _createAll.Field;
var Fields = _createAll.Fields;
var FieldArray = _createAll.FieldArray;

@@ -45,2 +46,2 @@ var focus = _createAll.focus;

var values = _createAll.values;
export { actionTypes, arrayInsert, arrayMove, arrayPop, arrayPush, arrayRemove, arrayRemoveAll, arrayShift, arraySplice, arraySwap, arrayUnshift, blur, change, destroy, Field, FieldArray, focus, formValueSelector, getFormValues, initialize, isDirty, isInvalid, isPristine, isValid, propTypes, reducer, reduxForm, reset, setSubmitFailed, setSubmitSucceeded, startAsyncValidation, startSubmit, stopAsyncValidation, stopSubmit, SubmissionError, touch, untouch, values };
export { actionTypes, arrayInsert, arrayMove, arrayPop, arrayPush, arrayRemove, arrayRemoveAll, arrayShift, arraySplice, arraySwap, arrayUnshift, blur, change, destroy, Field, Fields, FieldArray, focus, formValueSelector, getFormValues, initialize, isDirty, isInvalid, isPristine, isValid, propTypes, reducer, reduxForm, reset, setSubmitFailed, setSubmitSucceeded, startAsyncValidation, startSubmit, stopAsyncValidation, stopSubmit, SubmissionError, touch, untouch, values };

@@ -8,3 +8,3 @@ import { PropTypes } from 'react';

export var propTypes = {
var propTypes = {
// State:

@@ -15,2 +15,3 @@ asyncValidating: bool.isRequired, // true if async validation is running

invalid: bool.isRequired, // true if there are any validation errors
initialized: bool.isRequired, // true if the form has been initialized
pristine: bool.isRequired, // true if the values are the same as initialValues

@@ -24,5 +25,7 @@ submitting: bool.isRequired, // true if the form is in the process of being submitted

insert: func.isRequired, // function to insert a value into an array field
move: func.isRequired, // function to move a value within an array field
pop: func.isRequired, // function to pop a value off of an array field
push: func.isRequired, // function to push a value onto an array field
remove: func.isRequired, // function to remove a value from an array field
removeAll: func.isRequired, // function to remove all the values from an array field
shift: func.isRequired, // function to shift a value out of an array field

@@ -35,2 +38,3 @@ splice: func.isRequired, // function to splice a value into an array field

destroy: func.isRequired, // action to destroy the form's data in Redux
dispatch: func.isRequired, // the Redux dispatch action
handleSubmit: func.isRequired, // function to submit the form

@@ -41,2 +45,4 @@ initialize: func.isRequired, // action to initialize form data

untouch: func.isRequired // action to mark fields as untouched
};
};
export default propTypes;

@@ -20,2 +20,3 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var some = structure.some;
var deepEqual = structure.deepEqual;

@@ -30,6 +31,7 @@ var deleteInWithCleanUp = createDeleteInWithCleanUp(structure);

var result = state;
var nonValuesValue = value != null ? empty : undefined;
result = doSplice(result, 'values', field, index, removeNum, value, true);
result = doSplice(result, 'fields', field, index, removeNum, empty);
result = doSplice(result, 'submitErrors', field, index, removeNum, empty);
result = doSplice(result, 'asyncErrors', field, index, removeNum, empty);
result = doSplice(result, 'fields', field, index, removeNum, nonValuesValue);
result = doSplice(result, 'submitErrors', field, index, removeNum, nonValuesValue);
result = doSplice(result, 'asyncErrors', field, index, removeNum, nonValuesValue);
return result;

@@ -73,3 +75,4 @@ };

var field = _ref4.meta.field;
var payload = _ref4.payload;
var _ref4$payload = _ref4.payload;
var payload = _ref4$payload === undefined ? empty : _ref4$payload;

@@ -178,2 +181,3 @@ var array = getIn(state, 'values.' + field);

var payload = _ref14.payload;
var keepDirty = _ref14.meta.keepDirty;

@@ -186,3 +190,32 @@ var mapData = fromJS(payload);

}
result = setIn(result, 'values', mapData);
var newValues = mapData;
if (keepDirty && registeredFields) {
(function () {
//
// Keep the value of dirty fields while updating the value of
// pristine fields. This way, apps can reinitialize forms while
// avoiding stomping on user edits.
//
// Note 1: The initialize action replaces all initial values
// regardless of keepDirty.
//
// Note 2: When a field is dirty, keepDirty is enabled, and the field
// value is the same as the new initial value for the field, the
// initialize action causes the field to become pristine. That effect
// is what we want.
//
var previousValues = getIn(state, 'values');
var previousInitialValues = getIn(state, 'initial');
registeredFields.forEach(function (field) {
var name = field.name;
var previousInitialValue = getIn(previousInitialValues, name);
var previousValue = getIn(previousValues, name);
if (!deepEqual(previousValue, previousInitialValue)) {
// This field was dirty. Restore the dirty value.
newValues = setIn(newValues, name, previousValue);
}
});
})();
}
result = setIn(result, 'values', newValues);
result = setIn(result, 'initial', mapData);

@@ -319,2 +352,5 @@ return result;

}
if (fieldIndex < 0) {
return state;
}
return setIn(state, 'registeredFields', splice(registeredFields, fieldIndex, 1));

@@ -332,3 +368,17 @@ }), _defineProperty(_behaviors, UNTOUCH, function (state, _ref22) {

return Object.keys(payload).length ? setIn(state, 'syncErrors', payload) : deleteIn(state, 'syncErrors');
var result = state;
if (Object.keys(payload).length) {
var _error = payload._error;
var fieldErrors = _objectWithoutProperties(payload, ['_error']);
result = setIn(result, 'syncErrors', fieldErrors);
if (_error) {
result = setIn(result, 'error', _error);
}
} else {
result = deleteIn(result, 'error');
result = deleteIn(result, 'syncErrors');
}
return result;
}), _behaviors);

@@ -335,0 +385,0 @@

@@ -33,6 +33,5 @@ import _mapValues from 'lodash-es/mapValues';

import asyncValidation from './asyncValidation';
import createHasErrors from './hasErrors';
import createHasError from './hasError';
import defaultShouldAsyncValidate from './defaultShouldAsyncValidate';
import plain from './structure/plain';
import createIsValid from './selectors/isValid';

@@ -45,5 +44,7 @@ var isClassComponent = function isClassComponent(Component) {

var arrayInsert = importedActions.arrayInsert;
var arrayMove = importedActions.arrayMove;
var arrayPop = importedActions.arrayPop;
var arrayPush = importedActions.arrayPush;
var arrayRemove = importedActions.arrayRemove;
var arrayRemoveAll = importedActions.arrayRemoveAll;
var arrayShift = importedActions.arrayShift;

@@ -57,9 +58,11 @@ var arraySplice = importedActions.arraySplice;

var formActions = _objectWithoutProperties(importedActions, ['arrayInsert', 'arrayPop', 'arrayPush', 'arrayRemove', 'arrayShift', 'arraySplice', 'arraySwap', 'arrayUnshift', 'blur', 'change', 'focus']);
var formActions = _objectWithoutProperties(importedActions, ['arrayInsert', 'arrayMove', 'arrayPop', 'arrayPush', 'arrayRemove', 'arrayRemoveAll', 'arrayShift', 'arraySplice', 'arraySwap', 'arrayUnshift', 'blur', 'change', 'focus']);
var arrayActions = {
arrayInsert: arrayInsert,
arrayMove: arrayMove,
arrayPop: arrayPop,
arrayPush: arrayPush,
arrayRemove: arrayRemove,
arrayRemoveAll: arrayRemoveAll,
arrayShift: arrayShift,

@@ -89,7 +92,4 @@ arraySplice: arraySplice,

var fromJS = structure.fromJS;
var some = structure.some;
var hasErrors = createHasErrors(structure);
var hasError = createHasError(structure);
var plainHasErrors = createHasErrors(plain);
var isValid = createIsValid(structure);
return function (initialConfig) {

@@ -102,5 +102,7 @@ var config = _extends({

enableReinitialize: false,
keepDirtyOnReinitialize: false,
getFormState: function getFormState(state) {
return getIn(state, 'form');
}
},
pure: true
}, initialConfig);

@@ -146,9 +148,10 @@ return function (WrappedComponent) {

value: function initIfNeeded(nextProps) {
var enableReinitialize = this.props.enableReinitialize;
if (nextProps) {
var enableReinitialize = this.props.enableReinitialize;
if ((enableReinitialize || !nextProps.initialized) && !deepEqual(this.props.initialValues, nextProps.initialValues)) {
this.props.initialize(nextProps.initialValues);
var keepDirty = nextProps.initialized && this.props.keepDirtyOnReinitialize;
this.props.initialize(nextProps.initialValues, keepDirty);
}
} else if (this.props.initialValues) {
} else if (this.props.initialValues && (!this.props.initialized || enableReinitialize)) {
this.props.initialize(this.props.initialValues);

@@ -208,2 +211,3 @@ }

if (!config.pure) return true;
return Object.keys(nextProps).some(function (prop) {

@@ -297,3 +301,3 @@ // useful to debug rerenders

v: asyncValidation(function () {
return asyncValidate(valuesToValidate, dispatch, _this4.props);
return asyncValidate(valuesToValidate, dispatch, _this4.props, name);
}, startAsyncValidation, stopAsyncValidation, name)

@@ -360,5 +364,7 @@ };

var arrayInsert = _props5.arrayInsert;
var arrayMove = _props5.arrayMove;
var arrayPop = _props5.arrayPop;
var arrayPush = _props5.arrayPush;
var arrayRemove = _props5.arrayRemove;
var arrayRemoveAll = _props5.arrayRemoveAll;
var arrayShift = _props5.arrayShift;

@@ -371,2 +377,4 @@ var arraySplice = _props5.arraySplice;

var asyncValidating = _props5.asyncValidating;
var blur = _props5.blur;
var change = _props5.change;
var destroy = _props5.destroy;

@@ -378,10 +386,22 @@ var destroyOnUnmount = _props5.destroyOnUnmount;

var error = _props5.error;
var focus = _props5.focus;
var form = _props5.form;
var getFormState = _props5.getFormState;
var initialize = _props5.initialize;
var initialized = _props5.initialized;
var initialValues = _props5.initialValues;
var invalid = _props5.invalid;
var keepDirtyOnReinitialize = _props5.keepDirtyOnReinitialize;
var pristine = _props5.pristine;
var propNamespace = _props5.propNamespace;
var registeredFields = _props5.registeredFields;
var registerField = _props5.registerField;
var reset = _props5.reset;
var setSubmitFailed = _props5.setSubmitFailed;
var setSubmitSucceeded = _props5.setSubmitSucceeded;
var shouldAsyncValidate = _props5.shouldAsyncValidate;
var startAsyncValidation = _props5.startAsyncValidation;
var startSubmit = _props5.startSubmit;
var stopAsyncValidation = _props5.stopAsyncValidation;
var stopSubmit = _props5.stopSubmit;
var submitting = _props5.submitting;

@@ -396,6 +416,7 @@ var submitFailed = _props5.submitFailed;

var untouch = _props5.untouch;
var updateSyncErrors = _props5.updateSyncErrors;
var valid = _props5.valid;
var values = _props5.values;
var rest = _objectWithoutProperties(_props5, ['anyTouched', 'arrayInsert', 'arrayPop', 'arrayPush', 'arrayRemove', 'arrayShift', 'arraySplice', 'arraySwap', 'arrayUnshift', 'asyncErrors', 'asyncValidate', 'asyncValidating', 'destroy', 'destroyOnUnmount', 'dirty', 'dispatch', 'enableReinitialize', 'error', 'form', 'getFormState', 'initialize', 'invalid', 'pristine', 'propNamespace', 'registerField', 'reset', 'submitting', 'submitFailed', 'submitSucceeded', 'touch', 'touchOnBlur', 'touchOnChange', 'syncErrors', 'unregisterField', 'untouch', 'valid', 'values']);
var rest = _objectWithoutProperties(_props5, ['anyTouched', 'arrayInsert', 'arrayMove', 'arrayPop', 'arrayPush', 'arrayRemove', 'arrayRemoveAll', 'arrayShift', 'arraySplice', 'arraySwap', 'arrayUnshift', 'asyncErrors', 'asyncValidate', 'asyncValidating', 'blur', 'change', 'destroy', 'destroyOnUnmount', 'dirty', 'dispatch', 'enableReinitialize', 'error', 'focus', 'form', 'getFormState', 'initialize', 'initialized', 'initialValues', 'invalid', 'keepDirtyOnReinitialize', 'pristine', 'propNamespace', 'registeredFields', 'registerField', 'reset', 'setSubmitFailed', 'setSubmitSucceeded', 'shouldAsyncValidate', 'startAsyncValidation', 'startSubmit', 'stopAsyncValidation', 'stopSubmit', 'submitting', 'submitFailed', 'submitSucceeded', 'touch', 'touchOnBlur', 'touchOnChange', 'syncErrors', 'unregisterField', 'untouch', 'updateSyncErrors', 'valid', 'values']);
/* eslint-enable no-unused-vars */

@@ -406,3 +427,3 @@

anyTouched: anyTouched,
asyncValidate: asyncValidate,
asyncValidate: this.asyncValidate,
asyncValidating: asyncValidating,

@@ -416,2 +437,3 @@ destroy: destroy,

initialize: initialize,
initialized: initialized,
invalid: invalid,

@@ -468,12 +490,5 @@ pristine: pristine,

var asyncErrors = getIn(formState, 'asyncErrors');
var submitErrors = getIn(formState, 'submitErrors');
var syncErrors = getIn(formState, 'syncErrors');
var hasSyncErrors = plainHasErrors(syncErrors);
var hasAsyncErrors = hasErrors(asyncErrors);
var hasSubmitErrors = hasErrors(submitErrors);
var registeredFields = getIn(formState, 'registeredFields') || [];
var hasFieldWithError = registeredFields && some(registeredFields, function (field) {
return hasError(field, syncErrors, asyncErrors, submitErrors);
});
var valid = !hasSyncErrors && !hasAsyncErrors && !hasSubmitErrors && !hasFieldWithError;
var valid = isValid(form, getFormState)(state);
var anyTouched = !!getIn(formState, 'anyTouched');

@@ -487,3 +502,3 @@ var submitting = !!getIn(formState, 'submitting');

asyncErrors: asyncErrors,
asyncValidating: getIn(formState, 'asyncValidating'),
asyncValidating: getIn(formState, 'asyncValidating') || false,
dirty: !pristine,

@@ -522,5 +537,7 @@ error: error,

insert: bindActionCreators(boundArrayACs.arrayInsert, dispatch),
move: bindActionCreators(boundArrayACs.arrayMove, dispatch),
pop: bindActionCreators(boundArrayACs.arrayPop, dispatch),
push: bindActionCreators(boundArrayACs.arrayPush, dispatch),
remove: bindActionCreators(boundArrayACs.arrayRemove, dispatch),
removeAll: bindActionCreators(boundArrayACs.arrayRemoveAll, dispatch),
shift: bindActionCreators(boundArrayACs.arrayShift, dispatch),

@@ -527,0 +544,0 @@ splice: bindActionCreators(boundArrayACs.arraySplice, dispatch),

@@ -24,3 +24,3 @@ import expect from 'expect';

toEqualMap: function toEqualMap(expected) {
expect.assert(deepEqualValues(this.actual, fromJS(expected)), 'expected...\n%s\n...but found...\n%s', this.actual, fromJS(expected));
expect.assert(deepEqualValues(this.actual, fromJS(expected)), 'expected...\n%s\n...but found...\n%s', fromJS(expected), this.actual);
return this;

@@ -27,0 +27,0 @@ }

@@ -5,2 +5,3 @@ import _toPath from 'lodash-es/toPath';

import deepEqual from './deepEqual';
import splice from './splice';
import plainGetIn from '../plain/getIn';

@@ -31,18 +32,5 @@

},
splice: function splice() {
var list = arguments.length <= 0 || arguments[0] === undefined ? List.isList(list) || List() : arguments[0];
var index = arguments[1];
var removeNum = arguments[2];
var value = arguments[3];
if (removeNum) {
return list.splice(index, removeNum); // removing
}
if (index < list.size) {
return list.splice(index, 0, value); // inserting
}
return list.set(index, value); // inserting after end of list
}
splice: splice
};
export default structure;

@@ -34,2 +34,6 @@ import expect from 'expect';

it('should remove in the middle then insert in that position', function () {
expect(splice(['a', 'b', 'c', 'd'], 1, 1, 'e')).toBeA('array').toEqual(['a', 'e', 'c', 'd']);
});
it('should remove at end', function () {

@@ -36,0 +40,0 @@ expect(splice(['a', 'b', 'c', 'd'], 3, 1)).toBeA('array').toEqual(['a', 'b', 'c']);

@@ -9,15 +9,21 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

var copy = [].concat(_toConsumableArray(array));
if (removeNum) {
copy.splice(index, removeNum); // removing
} else {
if (index < copy.length) {
copy.splice(index, 0, value); // adding
if (index < array.length) {
if (value != null) {
var copy = [].concat(_toConsumableArray(array));
copy.splice(index, removeNum, value); // removing and adding
return copy;
} else {
copy[index] = value; // outside range, so just set it
var _copy = [].concat(_toConsumableArray(array));
_copy.splice(index, removeNum); // removing
return _copy;
}
}
return copy;
if (value != null) {
var _copy2 = [].concat(_toConsumableArray(array));
_copy2[index] = value;
return _copy2;
}
return array;
};
export default splice;

@@ -232,3 +232,4 @@ 'use strict';

meta: {
form: 'myForm'
form: 'myForm',
keepDirty: undefined
},

@@ -239,2 +240,14 @@ payload: data

it('should create initialize action with a keepDirty value', function () {
var data = { a: 8, c: 9 };
(0, _expect2.default)((0, _actions.initialize)('myForm', data, true)).toEqual({
type: _actionTypes.INITIALIZE,
meta: {
form: 'myForm',
keepDirty: true
},
payload: data
}).toPass(_fluxStandardAction.isFSA);
});
it('should create registerField action', function () {

@@ -241,0 +254,0 @@ (0, _expect2.default)((0, _actions.registerField)('myForm', 'foo', 'Field')).toEqual({

'use strict';
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _expect = require('expect');

@@ -31,2 +33,4 @@

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var describeCreateFieldProps = function describeCreateFieldProps(name, structure, expect) {

@@ -238,2 +242,40 @@ var fromJS = structure.fromJS;

it('should provide reduce', function () {
var callback = (0, _expect.createSpy)(function (accumulator, name) {
return _extends({}, accumulator, _defineProperty({}, name, { whatever: true, name: name }));
}).andCallThrough();
var result = _createFieldArrayProps2.default.apply(undefined, defaultProps.concat([{
value: fromJS(['a', 'b', 'c'])
}]));
expect(result.fields.reduce).toBeA('function');
expect(callback).toNotHaveBeenCalled();
var reduceResult = result.fields.reduce(callback, {});
expect(size(reduceResult), 3);
expect(reduceResult['foo[0]']).toEqual({ whatever: true, name: 'foo[0]' });
expect(reduceResult['foo[1]']).toEqual({ whatever: true, name: 'foo[1]' });
expect(reduceResult['foo[2]']).toEqual({ whatever: true, name: 'foo[2]' });
expect(callback).toHaveBeenCalled();
expect(callback.calls.length).toBe(3);
expect(callback.calls[0].arguments).toEqual([{}, 'foo[0]', 0]);
expect(callback.calls[1].arguments).toEqual([{
'foo[0]': { whatever: true, name: 'foo[0]' }
}, 'foo[1]', 1]);
expect(callback.calls[2].arguments).toEqual([{
'foo[0]': { whatever: true, name: 'foo[0]' },
'foo[1]': { whatever: true, name: 'foo[1]' }
}, 'foo[2]', 2]);
});
it('should provide reduce when no value', function () {
var callback = (0, _expect.createSpy)(function (accumulator, name) {
return _extends({}, accumulator, _defineProperty({}, name, { whatever: true, name: name }));
}).andCallThrough();
var result = _createFieldArrayProps2.default.apply(undefined, defaultProps.concat([{}]));
expect(result.fields.reduce).toBeA('function');
expect(callback).toNotHaveBeenCalled();
var reduceResult = result.fields.reduce(callback, {});
expect(size(reduceResult), 0);
expect(callback).toNotHaveBeenCalled();
});
it('should provide swap', function () {

@@ -250,2 +292,9 @@ var arraySwap = (0, _expect.createSpy)();

});
it('should provide a _isFieldArray meta prop', function () {
var result = _createFieldArrayProps2.default.apply(undefined, defaultProps.concat([{
value: fromJS(['a', 'b', 'c'])
}]));
expect(result.fields._isFieldArray).toBe(true);
});
});

@@ -252,0 +301,0 @@ };

@@ -51,12 +51,15 @@ 'use strict';

var blur = (0, _expect.createSpy)();
var normalize = (0, _expect.createSpy)(function (value) {
var dispatch = (0, _expect.createSpy)();
var normalize = (0, _expect.createSpy)(function (name, value) {
return value;
}).andCallThrough();
expect(blur).toNotHaveBeenCalled();
var result = (0, _createFieldProps2.default)(getIn, 'foo', { value: 'bar', blur: blur, normalize: normalize });
var result = (0, _createFieldProps2.default)(getIn, 'foo', { value: 'bar', blur: blur, dispatch: dispatch, normalize: normalize });
expect(result.input.onBlur).toBeA('function');
expect(blur).toNotHaveBeenCalled();
expect(dispatch).toNotHaveBeenCalled();
result.input.onBlur('rabbit');
expect(normalize).toHaveBeenCalled();
expect(blur).toHaveBeenCalled().toHaveBeenCalledWith('rabbit');
expect(blur).toHaveBeenCalled().toHaveBeenCalledWith('foo', 'rabbit');
expect(dispatch).toHaveBeenCalled();
});

@@ -66,12 +69,15 @@

var change = (0, _expect.createSpy)();
var normalize = (0, _expect.createSpy)(function (value) {
var dispatch = (0, _expect.createSpy)();
var normalize = (0, _expect.createSpy)(function (name, value) {
return value;
}).andCallThrough();
expect(change).toNotHaveBeenCalled();
var result = (0, _createFieldProps2.default)(getIn, 'foo', { value: 'bar', change: change, normalize: normalize });
var result = (0, _createFieldProps2.default)(getIn, 'foo', { value: 'bar', change: change, dispatch: dispatch, normalize: normalize });
expect(result.input.onChange).toBeA('function');
expect(change).toNotHaveBeenCalled();
expect(dispatch).toNotHaveBeenCalled();
result.input.onChange('rabbit');
expect(normalize).toHaveBeenCalled();
expect(change).toHaveBeenCalled().toHaveBeenCalledWith('rabbit');
expect(change).toHaveBeenCalled().toHaveBeenCalledWith('foo', 'rabbit');
expect(dispatch).toHaveBeenCalled();
});

@@ -81,8 +87,11 @@

var focus = (0, _expect.createSpy)();
var dispatch = (0, _expect.createSpy)();
expect(focus).toNotHaveBeenCalled();
var result = (0, _createFieldProps2.default)(getIn, 'foo', { value: 'bar', focus: focus });
var result = (0, _createFieldProps2.default)(getIn, 'foo', { value: 'bar', dispatch: dispatch, focus: focus });
expect(result.input.onFocus).toBeA('function');
expect(focus).toNotHaveBeenCalled();
expect(dispatch).toNotHaveBeenCalled();
result.input.onFocus('rabbit');
expect(focus).toHaveBeenCalled().toHaveBeenCalledWith('foo');
expect(dispatch).toHaveBeenCalled();
});

@@ -115,2 +124,14 @@

it('should pass along submitting flag', function () {
var notSubmittingResult = (0, _createFieldProps2.default)(getIn, 'foo', {
value: 'bar'
});
expect(notSubmittingResult.meta.submitting).toBe(false);
var submittingResult = (0, _createFieldProps2.default)(getIn, 'foo', {
value: 'bar',
submitting: true
});
expect(submittingResult.meta.submitting).toBe(true);
});
it('should read touched from state', function () {

@@ -117,0 +138,0 @@ var untouchedResult = (0, _createFieldProps2.default)(getIn, 'foo', {

@@ -178,2 +178,25 @@ 'use strict';

it('should allow an empty value from Redux state to be pristine', function () {
var props1 = testProps({
initial: {
foo: 'bar'
},
values: {
foo: ''
}
});
expect(props1.meta.pristine).toBe(false);
expect(props1.meta.dirty).toBe(true);
var props2 = testProps({
initial: {
foo: ''
},
values: {
foo: ''
}
});
expect(props2.meta.pristine).toBe(true);
expect(props2.meta.dirty).toBe(false);
});
it('should get asyncValidating from Redux state', function () {

@@ -716,7 +739,4 @@ var props1 = testProps({

it('should rerender when props change', function () {
it('should re-register when name changes', function () {
var store = makeStore();
var input = (0, _expect.createSpy)(function (props) {
return _react2.default.createElement('input', props.input);
}).andCallThrough();

@@ -731,3 +751,3 @@ var Form = function (_Component13) {

_this14.state = { foo: 'foo' };
_this14.state = { field: 'foo' };
return _this14;

@@ -744,2 +764,70 @@ }

null,
_react2.default.createElement(Field, { name: this.state.field, component: 'input' }),
_react2.default.createElement(
'button',
{ onClick: function onClick() {
return _this15.setState({ field: 'bar' });
} },
'Change'
)
);
}
}]);
return Form;
}(_react.Component);
var TestForm = reduxForm({ form: 'testForm' })(Form);
var dom = _reactAddonsTestUtils2.default.renderIntoDocument(_react2.default.createElement(
_reactRedux.Provider,
{ store: store },
_react2.default.createElement(TestForm, null)
));
expect(store.getState()).toEqualMap({
form: {
testForm: {
registeredFields: [{ name: 'foo', type: 'Field' }]
}
}
});
var button = _reactAddonsTestUtils2.default.findRenderedDOMComponentWithTag(dom, 'button');
_reactAddonsTestUtils2.default.Simulate.click(button);
expect(store.getState()).toEqualMap({
form: {
testForm: {
registeredFields: [{ name: 'bar', type: 'Field' }]
}
}
});
});
it('should rerender when props change', function () {
var store = makeStore();
var input = (0, _expect.createSpy)(function (props) {
return _react2.default.createElement('input', props.input);
}).andCallThrough();
var Form = function (_Component14) {
_inherits(Form, _Component14);
function Form() {
_classCallCheck(this, Form);
var _this16 = _possibleConstructorReturn(this, Object.getPrototypeOf(Form).call(this));
_this16.state = { foo: 'foo' };
return _this16;
}
_createClass(Form, [{
key: 'render',
value: function render() {
var _this17 = this;
return _react2.default.createElement(
'div',
null,
_react2.default.createElement(Field, { name: 'foo', rel: this.state.foo, component: input }),

@@ -749,3 +837,3 @@ _react2.default.createElement(

{ onClick: function onClick() {
return _this15.setState({ foo: 'qux' });
return _this17.setState({ foo: 'qux' });
} },

@@ -785,4 +873,4 @@ 'Change'

var Form = function (_Component14) {
_inherits(Form, _Component14);
var Form = function (_Component15) {
_inherits(Form, _Component15);

@@ -792,6 +880,6 @@ function Form() {

var _this16 = _possibleConstructorReturn(this, Object.getPrototypeOf(Form).call(this));
var _this18 = _possibleConstructorReturn(this, Object.getPrototypeOf(Form).call(this));
_this16.state = { foo: 'bar' };
return _this16;
_this18.state = { foo: 'bar' };
return _this18;
}

@@ -802,3 +890,3 @@

value: function render() {
var _this17 = this;
var _this19 = this;

@@ -813,3 +901,3 @@ renderSpy();

{ onClick: function onClick() {
return _this17.setState({ foo: 'qux' });
return _this19.setState({ foo: 'qux' });
} },

@@ -863,4 +951,4 @@ 'Change'

var Form = function (_Component15) {
_inherits(Form, _Component15);
var Form = function (_Component16) {
_inherits(Form, _Component16);

@@ -932,4 +1020,4 @@ function Form() {

var Form = function (_Component16) {
_inherits(Form, _Component16);
var Form = function (_Component17) {
_inherits(Form, _Component17);

@@ -999,4 +1087,4 @@ function Form() {

var Form = function (_Component17) {
_inherits(Form, _Component17);
var Form = function (_Component18) {
_inherits(Form, _Component18);

@@ -1052,4 +1140,4 @@ function Form() {

var Form = function (_Component18) {
_inherits(Form, _Component18);
var Form = function (_Component19) {
_inherits(Form, _Component19);

@@ -1113,4 +1201,4 @@ function Form() {

var Form = function (_Component19) {
_inherits(Form, _Component19);
var Form = function (_Component20) {
_inherits(Form, _Component20);

@@ -1177,4 +1265,4 @@ function Form() {

var Form = function (_Component20) {
_inherits(Form, _Component20);
var Form = function (_Component21) {
_inherits(Form, _Component21);

@@ -1270,4 +1358,4 @@ function Form() {

var Form = function (_Component21) {
_inherits(Form, _Component21);
var Form = function (_Component22) {
_inherits(Form, _Component22);

@@ -1337,4 +1425,4 @@ function Form() {

var Form = function (_Component22) {
_inherits(Form, _Component22);
var Form = function (_Component23) {
_inherits(Form, _Component23);

@@ -1341,0 +1429,0 @@ function Form() {

@@ -45,2 +45,6 @@ 'use strict';

var _Fields = require('../Fields');
var _Fields2 = _interopRequireDefault(_Fields);
var _plain = require('../structure/plain');

@@ -81,2 +85,3 @@

var Field = (0, _Field2.default)(structure);
var Fields = (0, _Fields2.default)(structure);
var reducer = (0, _reducer2.default)(structure);

@@ -1132,2 +1137,71 @@ var fromJS = structure.fromJS;

});
it('should work with Fields', function () {
var store = makeStore({
testForm: {
values: {
foo: ['firstValue', 'secondValue']
}
}
});
var renderField = (0, _expect.createSpy)(function (field) {
return _react2.default.createElement('input', field.input);
});
var renderFields = (0, _expect.createSpy)(function (_ref3) {
var foo = _ref3.foo;
return _react2.default.createElement(
'div',
null,
foo.map(renderField)
);
}).andCallThrough();
var component = (0, _expect.createSpy)(function (_ref4) {
var fields = _ref4.fields;
return _react2.default.createElement(
'div',
null,
_react2.default.createElement(Fields, { names: fields, component: renderFields })
);
}).andCallThrough();
var Form = function (_Component17) {
_inherits(Form, _Component17);
function Form() {
_classCallCheck(this, Form);
return _possibleConstructorReturn(this, Object.getPrototypeOf(Form).apply(this, arguments));
}
_createClass(Form, [{
key: 'render',
value: function render() {
return _react2.default.createElement(
'div',
null,
_react2.default.createElement(FieldArray, { name: 'foo', component: component })
);
}
}]);
return Form;
}(_react.Component);
var TestForm = reduxForm({ form: 'testForm' })(Form);
_reactAddonsTestUtils2.default.renderIntoDocument(_react2.default.createElement(
_reactRedux.Provider,
{ store: store },
_react2.default.createElement(TestForm, null)
));
expect(renderFields).toHaveBeenCalled();
expect(renderFields.calls.length).toBe(1);
expect(renderFields.calls[0].arguments[0].foo.length).toBe(2);
expect(renderField).toHaveBeenCalled();
expect(renderField.calls.length).toBe(2);
expect(renderField.calls[0].arguments[0].input.value).toBe('firstValue');
expect(renderField.calls[1].arguments[0].input.value).toBe('secondValue');
});
};

@@ -1134,0 +1208,0 @@

@@ -97,3 +97,3 @@ 'use strict';

it('should not submit if async validation fails', function (done) {
it('should not submit if async validation fails', function () {
var values = { foo: 'bar', baz: 42 };

@@ -119,7 +119,6 @@ var submit = (0, _expect.createSpy)().andReturn(69);

(0, _expect2.default)(setSubmitFailed).toHaveBeenCalled().toHaveBeenCalledWith('foo', 'baz');
done();
});
});
it('should not submit if async validation fails and return rejected promise', function (done) {
it('should not submit if async validation fails and return rejected promise', function () {
var values = { foo: 'bar', baz: 42 };

@@ -148,3 +147,2 @@ var submit = (0, _expect.createSpy)().andReturn(69);

(0, _expect2.default)(setSubmitFailed).toHaveBeenCalled().toHaveBeenCalledWith('foo', 'baz');
done();
});

@@ -201,3 +199,3 @@ });

it('should set submit errors if async submit fails', function (done) {
it('should set submit errors if async submit fails', function () {
var values = { foo: 'bar', baz: 42 };

@@ -224,7 +222,6 @@ var submitErrors = { foo: 'submit error' };

(0, _expect2.default)(setSubmitSucceeded).toNotHaveBeenCalled();
done();
});
});
it('should not set errors if rejected value not a SubmissionError', function (done) {
it('should not set errors if rejected value not a SubmissionError', function () {
var values = { foo: 'bar', baz: 42 };

@@ -251,7 +248,6 @@ var submitErrors = { foo: 'submit error' };

(0, _expect2.default)(setSubmitSucceeded).toNotHaveBeenCalled();
done();
});
});
it('should set submit errors if async submit fails and return rejected promise', function (done) {
it('should set submit errors if async submit fails and return rejected promise', function () {
var values = { foo: 'bar', baz: 42 };

@@ -280,5 +276,4 @@ var submitErrors = { foo: 'submit error' };

(0, _expect2.default)(setSubmitSucceeded).toNotHaveBeenCalled();
done();
});
});
});

@@ -133,2 +133,17 @@ 'use strict';

});
it('should return true if a Field that has an object value has an _error', function () {
var field = fromJS({ name: 'foo', type: 'Field' });
var plainError = {
foo: {
_error: 'An error'
}
};
expect(hasError(field, plainError)).toBe(true);
var error = fromJS(plainError);
expect(hasError(field, null, error)).toBe(true);
expect(hasError(field, null, null, error)).toBe(true);
});
});

@@ -135,0 +150,0 @@ };

@@ -161,2 +161,77 @@ 'use strict';

});
it('should retain dirty values when keepDirty is set', function () {
var state = reducer(fromJS({
foo: {
registeredFields: [{ name: 'myField', type: 'Field' }],
values: {
myField: 'dirtyValue'
},
initial: {
myField: 'initialValue'
}
}
}), (0, _actions.initialize)('foo', { myField: 'newValue' }, true));
expect(state).toEqualMap({
foo: {
registeredFields: [{ name: 'myField', type: 'Field' }],
values: {
myField: 'dirtyValue'
},
initial: {
myField: 'newValue'
}
}
});
});
it('should replace pristine values when keepDirty is set', function () {
var state = reducer(fromJS({
foo: {
registeredFields: [{ name: 'myField', type: 'Field' }],
values: {
myField: 'initialValue'
},
initial: {
myField: 'initialValue'
}
}
}), (0, _actions.initialize)('foo', { myField: 'newValue' }, true));
expect(state).toEqualMap({
foo: {
registeredFields: [{ name: 'myField', type: 'Field' }],
values: {
myField: 'newValue'
},
initial: {
myField: 'newValue'
}
}
});
});
it('should treat a matching dirty value as pristine when keepDirty is set', function () {
var state = reducer(fromJS({
foo: {
registeredFields: [{ name: 'myField', type: 'Field' }],
values: {
myField: 'newValue'
},
initial: {
myField: 'initialValue'
}
}
}), (0, _actions.initialize)('foo', { myField: 'newValue' }, true));
expect(state).toEqualMap({
foo: {
registeredFields: [{ name: 'myField', type: 'Field' }],
values: {
myField: 'newValue'
},
initial: {
myField: 'newValue'
}
}
});
});
};

@@ -163,0 +238,0 @@ };

@@ -30,2 +30,15 @@ 'use strict';

});
it('should do nothing if the field is not registered', function () {
var state = reducer(fromJS({
foo: {
registeredFields: [{ name: 'bar', type: 'field' }]
}
}), (0, _actions.unregisterField)('foo', 'baz'));
expect(state).toEqualMap({
foo: {
registeredFields: [{ name: 'bar', type: 'field' }]
}
});
});
};

@@ -32,0 +45,0 @@ };

@@ -38,2 +38,27 @@ 'use strict';

it('should update form-wide error', function () {
var state = reducer(fromJS({
foo: {
values: {
myField: 'value',
myOtherField: 'otherValue'
}
}
}), (0, _actions.updateSyncErrors)('foo', {
myField: 'myField error',
_error: 'form wide error'
}));
expect(state).toEqualMap(setIn(fromJS({
foo: {
values: {
myField: 'value',
myOtherField: 'otherValue'
},
error: 'form wide error'
}
}), 'foo.syncErrors', {
myField: 'myField error'
}));
});
it('should update complex sync errors', function () {

@@ -40,0 +65,0 @@ var state = reducer(fromJS({

@@ -79,4 +79,4 @@ 'use strict';

var initialize = exports.initialize = function initialize(form, values) {
return { type: _actionTypes.INITIALIZE, meta: { form: form }, payload: values };
var initialize = exports.initialize = function initialize(form, values, keepDirty) {
return { type: _actionTypes.INITIALIZE, meta: { form: form, keepDirty: keepDirty }, payload: values };
};

@@ -83,0 +83,0 @@

@@ -7,6 +7,2 @@ 'use strict';

var _mapValues2 = require('lodash/mapValues');
var _mapValues3 = _interopRequireDefault(_mapValues2);
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

@@ -96,3 +92,7 @@

var props = (0, _createFieldProps2.default)(getIn, name, rest, asyncValidate);
var props = (0, _createFieldProps2.default)(getIn, name, _extends({}, rest, {
blur: blur,
change: change,
focus: focus
}), asyncValidate);
if (withRef) {

@@ -125,13 +125,8 @@ props.ref = 'renderedComponent';

var actions = (0, _mapValues3.default)({
blur: blur,
change: change,
focus: focus
}, function (actionCreator) {
return actionCreator.bind(null, name);
});
var connector = (0, _reactRedux.connect)(function (state, ownProps) {
var formState = getFormState(state);
var initial = getIn(formState, 'initial.' + name) || propInitialValue;
var initialState = getIn(formState, 'initial.' + name);
var initial = initialState === undefined ? propInitialValue : initialState;
var value = getIn(formState, 'values.' + name);
var submitting = getIn(formState, 'submitting');
var syncError = getSyncError(getIn(formState, 'syncErrors'));

@@ -146,2 +141,3 @@ var pristine = value === initial;

submitError: getIn(formState, 'submitErrors.' + name),
submitting: submitting,
syncError: syncError,

@@ -151,3 +147,3 @@ value: value,

};
}, actions, undefined, { withRef: true });
}, undefined, undefined, { withRef: true });
return connector(ConnectedField);

@@ -154,0 +150,0 @@ };

@@ -152,2 +152,3 @@ 'use strict';

var value = getIn(formState, 'values.' + name);
var submitting = getIn(formState, 'submitting');
var syncError = getSyncError(getIn(formState, 'syncErrors'));

@@ -160,2 +161,3 @@ var pristine = deepEqual(value, initial);

submitError: getIn(formState, 'submitErrors.' + name + '._error'),
submitting: submitting,
syncError: syncError,

@@ -162,0 +164,0 @@ value: value

@@ -21,2 +21,6 @@ 'use strict';

var _Fields = require('./Fields');
var _Fields2 = _interopRequireDefault(_Fields);
var _FieldArray = require('./FieldArray');

@@ -80,2 +84,3 @@

Field: (0, _Field2.default)(structure),
Fields: (0, _Fields2.default)(structure),
FieldArray: (0, _FieldArray2.default)(structure),

@@ -82,0 +87,0 @@ formValueSelector: (0, _formValueSelector2.default)(structure),

@@ -27,2 +27,3 @@ "use strict";

var submitFailed = _ref.submitFailed;
var submitting = _ref.submitting;
var syncError = _ref.syncError;

@@ -32,3 +33,3 @@ var value = _ref.value;

var rest = _objectWithoutProperties(_ref, ["arrayInsert", "arrayMove", "arrayPop", "arrayPush", "arrayRemove", "arrayRemoveAll", "arrayShift", "arraySplice", "arraySwap", "arrayUnshift", "asyncError", "dirty", "pristine", "submitError", "submitFailed", "syncError", "value", "props"]);
var rest = _objectWithoutProperties(_ref, ["arrayInsert", "arrayMove", "arrayPop", "arrayPush", "arrayRemove", "arrayRemoveAll", "arrayShift", "arraySplice", "arraySwap", "arrayUnshift", "asyncError", "dirty", "pristine", "submitError", "submitFailed", "submitting", "syncError", "value", "props"]);

@@ -39,2 +40,3 @@ var error = syncError || asyncError || submitError;

fields: {
_isFieldArray: true,
forEach: function forEach(callback) {

@@ -58,2 +60,7 @@ return (value || []).forEach(function (item, index) {

push: arrayPush,
reduce: function reduce(callback, initial) {
return (value || []).reduce(function (accumulator, item, index) {
return callback(accumulator, name + "[" + index + "]", index);
}, initial);
},
remove: arrayRemove,

@@ -73,2 +80,3 @@ removeAll: arrayRemoveAll,

pristine: pristine,
submitting: submitting,
valid: !error

@@ -75,0 +83,0 @@ }

@@ -72,2 +72,3 @@ 'use strict';

var dirty = _ref.dirty;
var dispatch = _ref.dispatch;
var focus = _ref.focus;

@@ -81,2 +82,3 @@ var format = _ref.format;

var submitError = _ref.submitError;
var submitting = _ref.submitting;
var value = _ref.value;

@@ -86,3 +88,3 @@ var _value = _ref._value;

var custom = _objectWithoutProperties(_ref, ['asyncError', 'asyncValidating', 'blur', 'change', 'defaultValue', 'dirty', 'focus', 'format', 'normalize', 'parse', 'pristine', 'props', 'state', 'submitError', 'value', '_value', 'syncError']);
var custom = _objectWithoutProperties(_ref, ['asyncError', 'asyncValidating', 'blur', 'change', 'defaultValue', 'dirty', 'dispatch', 'focus', 'format', 'normalize', 'parse', 'pristine', 'props', 'state', 'submitError', 'submitting', 'value', '_value', 'syncError']);

@@ -92,3 +94,12 @@ var asyncValidate = arguments.length <= 3 || arguments[3] === undefined ? _noop3.default : arguments[3];

var error = syncError || asyncError || submitError;
var onChange = (0, _createOnChange2.default)(change, { normalize: normalize, parse: parse });
var boundNormalize = normalize && function (value) {
return normalize(name, value);
};
var boundChange = function boundChange(value) {
return dispatch(change(name, value));
};
var onChange = (0, _createOnChange2.default)(boundChange, {
normalize: boundNormalize,
parse: parse
});
var fieldValue = value == null ? defaultValue : value;

@@ -99,7 +110,15 @@

name: name,
onBlur: (0, _createOnBlur2.default)(blur, { normalize: normalize, parse: parse, after: asyncValidate.bind(null, name) }),
onBlur: (0, _createOnBlur2.default)(function (value) {
return dispatch(blur(name, value));
}, {
normalize: boundNormalize,
parse: parse,
after: asyncValidate.bind(null, name)
}),
onChange: onChange,
onDragStart: (0, _createOnDragStart2.default)(name, fieldValue),
onDrop: (0, _createOnDrop2.default)(name, change),
onFocus: (0, _createOnFocus2.default)(name, focus),
onDrop: (0, _createOnDrop2.default)(name, boundChange),
onFocus: (0, _createOnFocus2.default)(name, function () {
return dispatch(focus(name));
}),
value: format ? format(fieldValue) : fieldValue

@@ -114,2 +133,3 @@ }, _value),

pristine: pristine,
submitting: !!submitting,
touched: !!(state && getIn(state, 'touched')),

@@ -116,0 +136,0 @@ valid: !error,

@@ -73,2 +73,6 @@ 'use strict';

this.ConnectedField = (0, _ConnectedField2.default)(this.context._reduxForm, { deepEqual: deepEqual, getIn: getIn }, nextProps.name);
// unregister old name
this.context._reduxForm.unregister(this.props.name);
// register new name
this.context._reduxForm.register(nextProps.name, 'Field');
}

@@ -89,3 +93,3 @@ }

key: 'normalize',
value: function normalize(value) {
value: function normalize(name, value) {
var normalize = this.props.normalize;

@@ -98,3 +102,3 @@

var previousValue = this.value;
var nextValues = setIn(previousValues, this.props.name, value);
var nextValues = setIn(previousValues, name, value);
return normalize(value, previousValue, nextValues, previousValues);

@@ -101,0 +105,0 @@ }

@@ -13,8 +13,8 @@ 'use strict';

var getErrorKey = function getErrorKey(name, type) {
var getErrorKeys = function getErrorKeys(name, type) {
switch (type) {
case 'Field':
return name;
return [name, name + '._error'];
case 'FieldArray':
return name + '._error';
return [name + '._error'];
}

@@ -32,13 +32,23 @@ };

}
var errorKey = getErrorKey(name, type);
var syncError = (0, _getIn2.default)(syncErrors, errorKey);
if (syncError && typeof syncError === 'string') {
var errorKeys = getErrorKeys(name, type);
var syncError = errorKeys.reduce(function (error, errorKey) {
var curError = (0, _getIn2.default)(syncErrors, errorKey);
return curError ? error + curError : error;
}, null);
if (syncError != null) {
return true;
}
var asyncError = getIn(asyncErrors, errorKey);
if (asyncError && typeof asyncError === 'string') {
var asyncError = errorKeys.reduce(function (error, errorKey) {
var curError = getIn(asyncErrors, errorKey);
return curError ? error + curError : error;
}, null);
if (asyncError != null) {
return true;
}
var submitError = getIn(submitErrors, errorKey);
if (submitError && typeof submitError === 'string') {
var submitError = errorKeys.reduce(function (error, errorKey) {
var curError = getIn(submitErrors, errorKey);
return curError ? error + curError : error;
}, null);
if (submitError != null) {
return true;

@@ -45,0 +55,0 @@ }

@@ -6,3 +6,3 @@ 'use strict';

});
exports.values = exports.untouch = exports.touch = exports.SubmissionError = exports.stopSubmit = exports.stopAsyncValidation = exports.startSubmit = exports.startAsyncValidation = exports.setSubmitSucceeded = exports.setSubmitFailed = exports.reset = exports.reduxForm = exports.reducer = exports.propTypes = exports.isValid = exports.isPristine = exports.isInvalid = exports.isDirty = exports.initialize = exports.getFormValues = exports.formValueSelector = exports.focus = exports.FieldArray = exports.Field = exports.destroy = exports.change = exports.blur = exports.arrayUnshift = exports.arraySwap = exports.arraySplice = exports.arrayShift = exports.arrayRemoveAll = exports.arrayRemove = exports.arrayPush = exports.arrayPop = exports.arrayMove = exports.arrayInsert = exports.actionTypes = undefined;
exports.values = exports.untouch = exports.touch = exports.SubmissionError = exports.stopSubmit = exports.stopAsyncValidation = exports.startSubmit = exports.startAsyncValidation = exports.setSubmitSucceeded = exports.setSubmitFailed = exports.reset = exports.reduxForm = exports.reducer = exports.propTypes = exports.isValid = exports.isPristine = exports.isInvalid = exports.isDirty = exports.initialize = exports.getFormValues = exports.formValueSelector = exports.focus = exports.FieldArray = exports.Fields = exports.Field = exports.destroy = exports.change = exports.blur = exports.arrayUnshift = exports.arraySwap = exports.arraySplice = exports.arrayShift = exports.arrayRemoveAll = exports.arrayRemove = exports.arrayPush = exports.arrayPop = exports.arrayMove = exports.arrayInsert = exports.actionTypes = undefined;

@@ -36,2 +36,3 @@ var _createAll2 = require('./createAll');

var Field = _createAll.Field;
var Fields = _createAll.Fields;
var FieldArray = _createAll.FieldArray;

@@ -75,2 +76,3 @@ var focus = _createAll.focus;

exports.Field = Field;
exports.Fields = Fields;
exports.FieldArray = FieldArray;

@@ -77,0 +79,0 @@ exports.focus = focus;

@@ -6,3 +6,3 @@ 'use strict';

});
exports.values = exports.untouch = exports.touch = exports.SubmissionError = exports.stopSubmit = exports.stopAsyncValidation = exports.startSubmit = exports.startAsyncValidation = exports.setSubmitSucceeded = exports.setSubmitFailed = exports.reset = exports.reduxForm = exports.reducer = exports.propTypes = exports.isValid = exports.isPristine = exports.isInvalid = exports.isDirty = exports.initialize = exports.getFormValues = exports.formValueSelector = exports.focus = exports.FieldArray = exports.Field = exports.destroy = exports.change = exports.blur = exports.arrayUnshift = exports.arraySwap = exports.arraySplice = exports.arrayShift = exports.arrayRemoveAll = exports.arrayRemove = exports.arrayPush = exports.arrayPop = exports.arrayMove = exports.arrayInsert = exports.actionTypes = undefined;
exports.values = exports.untouch = exports.touch = exports.SubmissionError = exports.stopSubmit = exports.stopAsyncValidation = exports.startSubmit = exports.startAsyncValidation = exports.setSubmitSucceeded = exports.setSubmitFailed = exports.reset = exports.reduxForm = exports.reducer = exports.propTypes = exports.isValid = exports.isPristine = exports.isInvalid = exports.isDirty = exports.initialize = exports.getFormValues = exports.formValueSelector = exports.focus = exports.FieldArray = exports.Fields = exports.Field = exports.destroy = exports.change = exports.blur = exports.arrayUnshift = exports.arraySwap = exports.arraySplice = exports.arrayShift = exports.arrayRemoveAll = exports.arrayRemove = exports.arrayPush = exports.arrayPop = exports.arrayMove = exports.arrayInsert = exports.actionTypes = undefined;

@@ -36,2 +36,3 @@ var _createAll2 = require('./createAll');

var Field = _createAll.Field;
var Fields = _createAll.Fields;
var FieldArray = _createAll.FieldArray;

@@ -75,2 +76,3 @@ var focus = _createAll.focus;

exports.Field = Field;
exports.Fields = Fields;
exports.FieldArray = FieldArray;

@@ -77,0 +79,0 @@ exports.focus = focus;

@@ -6,3 +6,2 @@ 'use strict';

});
exports.propTypes = undefined;

@@ -15,3 +14,5 @@ var _react = require('react');

var shape = _react.PropTypes.shape;
var propTypes = exports.propTypes = {
var propTypes = {
// State:

@@ -22,2 +23,3 @@ asyncValidating: bool.isRequired, // true if async validation is running

invalid: bool.isRequired, // true if there are any validation errors
initialized: bool.isRequired, // true if the form has been initialized
pristine: bool.isRequired, // true if the values are the same as initialValues

@@ -31,5 +33,7 @@ submitting: bool.isRequired, // true if the form is in the process of being submitted

insert: func.isRequired, // function to insert a value into an array field
move: func.isRequired, // function to move a value within an array field
pop: func.isRequired, // function to pop a value off of an array field
push: func.isRequired, // function to push a value onto an array field
remove: func.isRequired, // function to remove a value from an array field
removeAll: func.isRequired, // function to remove all the values from an array field
shift: func.isRequired, // function to shift a value out of an array field

@@ -42,2 +46,3 @@ splice: func.isRequired, // function to splice a value into an array field

destroy: func.isRequired, // action to destroy the form's data in Redux
dispatch: func.isRequired, // the Redux dispatch action
handleSubmit: func.isRequired, // function to submit the form

@@ -48,2 +53,4 @@ initialize: func.isRequired, // action to initialize form data

untouch: func.isRequired // action to mark fields as untouched
};
};
exports.default = propTypes;

@@ -32,2 +32,3 @@ 'use strict';

var some = structure.some;
var deepEqual = structure.deepEqual;

@@ -42,6 +43,7 @@ var deleteInWithCleanUp = (0, _deleteInWithCleanUp2.default)(structure);

var result = state;
var nonValuesValue = value != null ? empty : undefined;
result = doSplice(result, 'values', field, index, removeNum, value, true);
result = doSplice(result, 'fields', field, index, removeNum, empty);
result = doSplice(result, 'submitErrors', field, index, removeNum, empty);
result = doSplice(result, 'asyncErrors', field, index, removeNum, empty);
result = doSplice(result, 'fields', field, index, removeNum, nonValuesValue);
result = doSplice(result, 'submitErrors', field, index, removeNum, nonValuesValue);
result = doSplice(result, 'asyncErrors', field, index, removeNum, nonValuesValue);
return result;

@@ -85,3 +87,4 @@ };

var field = _ref4.meta.field;
var payload = _ref4.payload;
var _ref4$payload = _ref4.payload;
var payload = _ref4$payload === undefined ? empty : _ref4$payload;

@@ -190,2 +193,3 @@ var array = getIn(state, 'values.' + field);

var payload = _ref14.payload;
var keepDirty = _ref14.meta.keepDirty;

@@ -198,3 +202,32 @@ var mapData = fromJS(payload);

}
result = setIn(result, 'values', mapData);
var newValues = mapData;
if (keepDirty && registeredFields) {
(function () {
//
// Keep the value of dirty fields while updating the value of
// pristine fields. This way, apps can reinitialize forms while
// avoiding stomping on user edits.
//
// Note 1: The initialize action replaces all initial values
// regardless of keepDirty.
//
// Note 2: When a field is dirty, keepDirty is enabled, and the field
// value is the same as the new initial value for the field, the
// initialize action causes the field to become pristine. That effect
// is what we want.
//
var previousValues = getIn(state, 'values');
var previousInitialValues = getIn(state, 'initial');
registeredFields.forEach(function (field) {
var name = field.name;
var previousInitialValue = getIn(previousInitialValues, name);
var previousValue = getIn(previousValues, name);
if (!deepEqual(previousValue, previousInitialValue)) {
// This field was dirty. Restore the dirty value.
newValues = setIn(newValues, name, previousValue);
}
});
})();
}
result = setIn(result, 'values', newValues);
result = setIn(result, 'initial', mapData);

@@ -331,2 +364,5 @@ return result;

}
if (fieldIndex < 0) {
return state;
}
return setIn(state, 'registeredFields', splice(registeredFields, fieldIndex, 1));

@@ -344,3 +380,17 @@ }), _defineProperty(_behaviors, _actionTypes.UNTOUCH, function (state, _ref22) {

return Object.keys(payload).length ? setIn(state, 'syncErrors', payload) : deleteIn(state, 'syncErrors');
var result = state;
if (Object.keys(payload).length) {
var _error = payload._error;
var fieldErrors = _objectWithoutProperties(payload, ['_error']);
result = setIn(result, 'syncErrors', fieldErrors);
if (_error) {
result = setIn(result, 'error', _error);
}
} else {
result = deleteIn(result, 'error');
result = deleteIn(result, 'syncErrors');
}
return result;
}), _behaviors);

@@ -347,0 +397,0 @@

@@ -55,10 +55,2 @@ 'use strict';

var _hasErrors = require('./hasErrors');
var _hasErrors2 = _interopRequireDefault(_hasErrors);
var _hasError = require('./hasError');
var _hasError2 = _interopRequireDefault(_hasError);
var _defaultShouldAsyncValidate = require('./defaultShouldAsyncValidate');

@@ -72,2 +64,6 @@

var _isValid = require('./selectors/isValid');
var _isValid2 = _interopRequireDefault(_isValid);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

@@ -95,5 +91,7 @@

var arrayInsert = importedActions.arrayInsert;
var arrayMove = importedActions.arrayMove;
var arrayPop = importedActions.arrayPop;
var arrayPush = importedActions.arrayPush;
var arrayRemove = importedActions.arrayRemove;
var arrayRemoveAll = importedActions.arrayRemoveAll;
var arrayShift = importedActions.arrayShift;

@@ -107,9 +105,11 @@ var arraySplice = importedActions.arraySplice;

var formActions = _objectWithoutProperties(importedActions, ['arrayInsert', 'arrayPop', 'arrayPush', 'arrayRemove', 'arrayShift', 'arraySplice', 'arraySwap', 'arrayUnshift', 'blur', 'change', 'focus']);
var formActions = _objectWithoutProperties(importedActions, ['arrayInsert', 'arrayMove', 'arrayPop', 'arrayPush', 'arrayRemove', 'arrayRemoveAll', 'arrayShift', 'arraySplice', 'arraySwap', 'arrayUnshift', 'blur', 'change', 'focus']);
var arrayActions = {
arrayInsert: arrayInsert,
arrayMove: arrayMove,
arrayPop: arrayPop,
arrayPush: arrayPush,
arrayRemove: arrayRemove,
arrayRemoveAll: arrayRemoveAll,
arrayShift: arrayShift,

@@ -139,7 +139,4 @@ arraySplice: arraySplice,

var fromJS = structure.fromJS;
var some = structure.some;
var hasErrors = (0, _hasErrors2.default)(structure);
var hasError = (0, _hasError2.default)(structure);
var plainHasErrors = (0, _hasErrors2.default)(_plain2.default);
var isValid = (0, _isValid2.default)(structure);
return function (initialConfig) {

@@ -152,5 +149,7 @@ var config = _extends({

enableReinitialize: false,
keepDirtyOnReinitialize: false,
getFormState: function getFormState(state) {
return getIn(state, 'form');
}
},
pure: true
}, initialConfig);

@@ -196,9 +195,10 @@ return function (WrappedComponent) {

value: function initIfNeeded(nextProps) {
var enableReinitialize = this.props.enableReinitialize;
if (nextProps) {
var enableReinitialize = this.props.enableReinitialize;
if ((enableReinitialize || !nextProps.initialized) && !deepEqual(this.props.initialValues, nextProps.initialValues)) {
this.props.initialize(nextProps.initialValues);
var keepDirty = nextProps.initialized && this.props.keepDirtyOnReinitialize;
this.props.initialize(nextProps.initialValues, keepDirty);
}
} else if (this.props.initialValues) {
} else if (this.props.initialValues && (!this.props.initialized || enableReinitialize)) {
this.props.initialize(this.props.initialValues);

@@ -258,2 +258,3 @@ }

if (!config.pure) return true;
return Object.keys(nextProps).some(function (prop) {

@@ -347,3 +348,3 @@ // useful to debug rerenders

v: (0, _asyncValidation2.default)(function () {
return asyncValidate(valuesToValidate, dispatch, _this4.props);
return asyncValidate(valuesToValidate, dispatch, _this4.props, name);
}, startAsyncValidation, stopAsyncValidation, name)

@@ -410,5 +411,7 @@ };

var arrayInsert = _props5.arrayInsert;
var arrayMove = _props5.arrayMove;
var arrayPop = _props5.arrayPop;
var arrayPush = _props5.arrayPush;
var arrayRemove = _props5.arrayRemove;
var arrayRemoveAll = _props5.arrayRemoveAll;
var arrayShift = _props5.arrayShift;

@@ -421,2 +424,4 @@ var arraySplice = _props5.arraySplice;

var asyncValidating = _props5.asyncValidating;
var blur = _props5.blur;
var change = _props5.change;
var destroy = _props5.destroy;

@@ -428,10 +433,22 @@ var destroyOnUnmount = _props5.destroyOnUnmount;

var error = _props5.error;
var focus = _props5.focus;
var form = _props5.form;
var getFormState = _props5.getFormState;
var initialize = _props5.initialize;
var initialized = _props5.initialized;
var initialValues = _props5.initialValues;
var invalid = _props5.invalid;
var keepDirtyOnReinitialize = _props5.keepDirtyOnReinitialize;
var pristine = _props5.pristine;
var propNamespace = _props5.propNamespace;
var registeredFields = _props5.registeredFields;
var registerField = _props5.registerField;
var reset = _props5.reset;
var setSubmitFailed = _props5.setSubmitFailed;
var setSubmitSucceeded = _props5.setSubmitSucceeded;
var shouldAsyncValidate = _props5.shouldAsyncValidate;
var startAsyncValidation = _props5.startAsyncValidation;
var startSubmit = _props5.startSubmit;
var stopAsyncValidation = _props5.stopAsyncValidation;
var stopSubmit = _props5.stopSubmit;
var submitting = _props5.submitting;

@@ -446,6 +463,7 @@ var submitFailed = _props5.submitFailed;

var untouch = _props5.untouch;
var updateSyncErrors = _props5.updateSyncErrors;
var valid = _props5.valid;
var values = _props5.values;
var rest = _objectWithoutProperties(_props5, ['anyTouched', 'arrayInsert', 'arrayPop', 'arrayPush', 'arrayRemove', 'arrayShift', 'arraySplice', 'arraySwap', 'arrayUnshift', 'asyncErrors', 'asyncValidate', 'asyncValidating', 'destroy', 'destroyOnUnmount', 'dirty', 'dispatch', 'enableReinitialize', 'error', 'form', 'getFormState', 'initialize', 'invalid', 'pristine', 'propNamespace', 'registerField', 'reset', 'submitting', 'submitFailed', 'submitSucceeded', 'touch', 'touchOnBlur', 'touchOnChange', 'syncErrors', 'unregisterField', 'untouch', 'valid', 'values']);
var rest = _objectWithoutProperties(_props5, ['anyTouched', 'arrayInsert', 'arrayMove', 'arrayPop', 'arrayPush', 'arrayRemove', 'arrayRemoveAll', 'arrayShift', 'arraySplice', 'arraySwap', 'arrayUnshift', 'asyncErrors', 'asyncValidate', 'asyncValidating', 'blur', 'change', 'destroy', 'destroyOnUnmount', 'dirty', 'dispatch', 'enableReinitialize', 'error', 'focus', 'form', 'getFormState', 'initialize', 'initialized', 'initialValues', 'invalid', 'keepDirtyOnReinitialize', 'pristine', 'propNamespace', 'registeredFields', 'registerField', 'reset', 'setSubmitFailed', 'setSubmitSucceeded', 'shouldAsyncValidate', 'startAsyncValidation', 'startSubmit', 'stopAsyncValidation', 'stopSubmit', 'submitting', 'submitFailed', 'submitSucceeded', 'touch', 'touchOnBlur', 'touchOnChange', 'syncErrors', 'unregisterField', 'untouch', 'updateSyncErrors', 'valid', 'values']);
/* eslint-enable no-unused-vars */

@@ -456,3 +474,3 @@

anyTouched: anyTouched,
asyncValidate: asyncValidate,
asyncValidate: this.asyncValidate,
asyncValidating: asyncValidating,

@@ -466,2 +484,3 @@ destroy: destroy,

initialize: initialize,
initialized: initialized,
invalid: invalid,

@@ -518,12 +537,5 @@ pristine: pristine,

var asyncErrors = getIn(formState, 'asyncErrors');
var submitErrors = getIn(formState, 'submitErrors');
var syncErrors = getIn(formState, 'syncErrors');
var hasSyncErrors = plainHasErrors(syncErrors);
var hasAsyncErrors = hasErrors(asyncErrors);
var hasSubmitErrors = hasErrors(submitErrors);
var registeredFields = getIn(formState, 'registeredFields') || [];
var hasFieldWithError = registeredFields && some(registeredFields, function (field) {
return hasError(field, syncErrors, asyncErrors, submitErrors);
});
var valid = !hasSyncErrors && !hasAsyncErrors && !hasSubmitErrors && !hasFieldWithError;
var valid = isValid(form, getFormState)(state);
var anyTouched = !!getIn(formState, 'anyTouched');

@@ -537,3 +549,3 @@ var submitting = !!getIn(formState, 'submitting');

asyncErrors: asyncErrors,
asyncValidating: getIn(formState, 'asyncValidating'),
asyncValidating: getIn(formState, 'asyncValidating') || false,
dirty: !pristine,

@@ -572,5 +584,7 @@ error: error,

insert: (0, _redux.bindActionCreators)(boundArrayACs.arrayInsert, dispatch),
move: (0, _redux.bindActionCreators)(boundArrayACs.arrayMove, dispatch),
pop: (0, _redux.bindActionCreators)(boundArrayACs.arrayPop, dispatch),
push: (0, _redux.bindActionCreators)(boundArrayACs.arrayPush, dispatch),
remove: (0, _redux.bindActionCreators)(boundArrayACs.arrayRemove, dispatch),
removeAll: (0, _redux.bindActionCreators)(boundArrayACs.arrayRemoveAll, dispatch),
shift: (0, _redux.bindActionCreators)(boundArrayACs.arrayShift, dispatch),

@@ -577,0 +591,0 @@ splice: (0, _redux.bindActionCreators)(boundArrayACs.arraySplice, dispatch),

@@ -38,3 +38,3 @@ 'use strict';

toEqualMap: function toEqualMap(expected) {
_expect2.default.assert(deepEqualValues(this.actual, (0, _immutable.fromJS)(expected)), 'expected...\n%s\n...but found...\n%s', this.actual, (0, _immutable.fromJS)(expected));
_expect2.default.assert(deepEqualValues(this.actual, (0, _immutable.fromJS)(expected)), 'expected...\n%s\n...but found...\n%s', (0, _immutable.fromJS)(expected), this.actual);
return this;

@@ -41,0 +41,0 @@ }

@@ -17,2 +17,6 @@ 'use strict';

var _splice = require('./splice');
var _splice2 = _interopRequireDefault(_splice);
var _getIn = require('../plain/getIn');

@@ -47,18 +51,5 @@

},
splice: function splice() {
var list = arguments.length <= 0 || arguments[0] === undefined ? _immutable.List.isList(list) || (0, _immutable.List)() : arguments[0];
var index = arguments[1];
var removeNum = arguments[2];
var value = arguments[3];
if (removeNum) {
return list.splice(index, removeNum); // removing
}
if (index < list.size) {
return list.splice(index, 0, value); // inserting
}
return list.set(index, value); // inserting after end of list
}
splice: _splice2.default
};
exports.default = structure;

@@ -43,2 +43,6 @@ 'use strict';

it('should remove in the middle then insert in that position', function () {
(0, _expect2.default)((0, _splice2.default)(['a', 'b', 'c', 'd'], 1, 1, 'e')).toBeA('array').toEqual(['a', 'e', 'c', 'd']);
});
it('should remove at end', function () {

@@ -45,0 +49,0 @@ (0, _expect2.default)((0, _splice2.default)(['a', 'b', 'c', 'd'], 3, 1)).toBeA('array').toEqual(['a', 'b', 'c']);

@@ -15,15 +15,21 @@ "use strict";

var copy = [].concat(_toConsumableArray(array));
if (removeNum) {
copy.splice(index, removeNum); // removing
} else {
if (index < copy.length) {
copy.splice(index, 0, value); // adding
if (index < array.length) {
if (value != null) {
var copy = [].concat(_toConsumableArray(array));
copy.splice(index, removeNum, value); // removing and adding
return copy;
} else {
copy[index] = value; // outside range, so just set it
var _copy = [].concat(_toConsumableArray(array));
_copy.splice(index, removeNum); // removing
return _copy;
}
}
return copy;
if (value != null) {
var _copy2 = [].concat(_toConsumableArray(array));
_copy2[index] = value;
return _copy2;
}
return array;
};
exports.default = splice;
{
"name": "redux-form",
"version": "6.0.0-rc.4",
"version": "6.0.0-rc.5",
"description": "A higher order component decorator for forms using Redux and React",

@@ -23,3 +23,3 @@ "main": "./lib/index.js",

"test:watch": "npm test -- --watch",
"test:cov": "babel-node ./node_modules/isparta/bin/isparta cover ./node_modules/mocha/bin/_mocha -- --recursive \"src/**/__tests__/*\" --require src/__tests__/setup.js",
"test:cov": "nyc --reporter=lcov --reporter=text npm test",
"test:codecov": "cat ./coverage/coverage.json | ./node_modules/codecov.io/bin/codecov.io.js"

@@ -64,3 +64,3 @@ },

"babel-polyfill": "^6.7.4",
"babel-preset-es2015": "^6.1.18",
"babel-preset-es2015": "6.9.0",
"babel-preset-es2015-webpack": "^6.4.1",

@@ -70,3 +70,3 @@ "babel-preset-react": "^6.1.18",

"babel-register": "^6.3.13",
"cross-env": "^1.0.7",
"cross-env": "^2.0.0",
"eslint": "^2.11.1",

@@ -80,6 +80,6 @@ "eslint-config-rackt": "^1.1.1",

"flux-standard-action": "^0.6.1",
"isparta": "4.0.0",
"jsdom": "^9.1.0",
"lodash-webpack-plugin": "^0.9.0",
"mocha": "^2.4.5",
"mocha": "^3.0.2",
"nyc": "^8.1.0",
"react": "^15.2.0",

@@ -86,0 +86,0 @@ "react-addons-test-utils": "^15.2.0",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc