redux-form
Advanced tools
Comparing version 6.0.2 to 6.0.3
@@ -193,3 +193,3 @@ import expect from 'expect'; | ||
it('should create change action', function () { | ||
expect(change('myForm', 'myField', 'bar', false)).toEqual({ | ||
expect(change('myForm', 'myField', 'bar', false, true)).toEqual({ | ||
type: CHANGE, | ||
@@ -199,7 +199,8 @@ meta: { | ||
field: 'myField', | ||
touch: false | ||
touch: false, | ||
persistentSubmitErrors: true | ||
}, | ||
payload: 'bar' | ||
}).toPass(isFSA); | ||
expect(change('myForm', 'myField', 7, true)).toEqual({ | ||
expect(change('myForm', 'myField', 7, true, false)).toEqual({ | ||
type: CHANGE, | ||
@@ -209,3 +210,4 @@ meta: { | ||
field: 'myField', | ||
touch: true | ||
touch: true, | ||
persistentSubmitErrors: false | ||
}, | ||
@@ -212,0 +214,0 @@ payload: 7 |
@@ -111,2 +111,31 @@ import { createSpy } from 'expect'; | ||
it('should pass along all custom state props', function () { | ||
var pristineResult = createFieldProps(getIn, 'foo', { | ||
value: 'bar' | ||
}); | ||
expect(pristineResult.meta.customProp).toBe(undefined); | ||
var customResult = createFieldProps(getIn, 'foo', { | ||
value: 'bar', | ||
state: { | ||
customProp: 'my-custom-prop' | ||
} | ||
}); | ||
expect(customResult.meta.customProp).toBe('my-custom-prop'); | ||
}); | ||
it('should not override canonical props with custom props', function () { | ||
var pristineResult = createFieldProps(getIn, 'foo', { | ||
value: 'bar' | ||
}); | ||
expect(pristineResult.meta.customProp).toBe(undefined); | ||
var customResult = createFieldProps(getIn, 'foo', { | ||
value: 'bar', | ||
submitting: true, | ||
state: { | ||
submitting: false | ||
} | ||
}); | ||
expect(customResult.meta.submitting).toBe(true); | ||
}); | ||
it('should read touched from state', function () { | ||
@@ -113,0 +142,0 @@ var untouchedResult = createFieldProps(getIn, 'foo', { |
@@ -160,2 +160,22 @@ 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 get touched from Redux state', function () { | ||
var props1 = testProps({ | ||
values: { | ||
foo: 'bar' | ||
} | ||
}); | ||
expect(props1.meta.touched).toBe(false); | ||
var props2 = testProps({ | ||
values: { | ||
foo: 'bar' | ||
}, | ||
fields: { | ||
foo: { | ||
touched: true | ||
} | ||
} | ||
}); | ||
expect(props2.meta.touched).toBe(true); | ||
}); | ||
it('should provide forEach', function () { | ||
@@ -162,0 +182,0 @@ var props = testProps({ |
@@ -258,2 +258,18 @@ import _noop from 'lodash-es/noop'; | ||
}); | ||
it('should submit when there are old submit errors and persistentSubmitErrors is enabled', function () { | ||
var values = { foo: 'bar', baz: 42 }; | ||
var submit = createSpy().andReturn(69); | ||
var startSubmit = createSpy(); | ||
var stopSubmit = createSpy(); | ||
var touch = createSpy(); | ||
var setSubmitFailed = createSpy(); | ||
var setSubmitSucceeded = createSpy(); | ||
var asyncValidate = createSpy(); | ||
var props = { startSubmit: startSubmit, stopSubmit: stopSubmit, touch: touch, setSubmitFailed: setSubmitFailed, setSubmitSucceeded: setSubmitSucceeded, values: values, persistentSubmitErrors: true }; | ||
handleSubmit(submit, props, true, asyncValidate, ['foo', 'baz']); | ||
expect(submit).toHaveBeenCalled(); | ||
}); | ||
}); |
@@ -206,2 +206,30 @@ import { change } from '../actions'; | ||
it('should NOT remove field-level submit errors and global errors if persistentSubmitErrors is enabled', function () { | ||
var state = reducer(fromJS({ | ||
foo: { | ||
values: { | ||
myField: 'initial' | ||
}, | ||
asyncErrors: { | ||
myField: 'async error' // only this will be removed | ||
}, | ||
submitErrors: { | ||
myField: 'submit error' | ||
}, | ||
error: 'some global error' | ||
} | ||
}), change('foo', 'myField', 'different', false, true)); | ||
expect(state).toEqualMap({ | ||
foo: { | ||
values: { | ||
myField: 'different' | ||
}, | ||
submitErrors: { | ||
myField: 'submit error' | ||
}, | ||
error: 'some global error' | ||
} | ||
}); | ||
}); | ||
it('should set nested value on change with empty state', function () { | ||
@@ -208,0 +236,0 @@ var state = reducer(undefined, change('foo', 'myField.mySubField', 'myValue', false)); |
@@ -34,3 +34,4 @@ import { setSubmitSucceeded } from '../actions'; | ||
should: 'change', | ||
submitSucceeded: true | ||
submitSucceeded: true, | ||
submitting: true | ||
} | ||
@@ -53,3 +54,4 @@ }); | ||
should: 'notchange', | ||
submitSucceeded: true | ||
submitSucceeded: true, | ||
submitting: true | ||
} | ||
@@ -56,0 +58,0 @@ }); |
@@ -179,3 +179,3 @@ import { stopSubmit } from '../actions'; | ||
it('should unset field submit errors on stopSubmit', function () { | ||
it('should unset field submit errors on stopSubmit with no errors', function () { | ||
var state = reducer(fromJS({ | ||
@@ -222,3 +222,3 @@ foo: { | ||
it('should unset global errors on stopSubmit', function () { | ||
it('should unset field submit errors on stopSubmit with global errors', function () { | ||
var state = reducer(fromJS({ | ||
@@ -229,2 +229,5 @@ foo: { | ||
}, | ||
submitErrors: { | ||
myField: 'some submit error' | ||
}, | ||
fields: { | ||
@@ -235,2 +238,32 @@ myField: { | ||
}, | ||
submitting: true | ||
} | ||
}), stopSubmit('foo', { _error: 'some global error' })); | ||
expect(state).toEqualMap({ | ||
foo: { | ||
values: { | ||
myField: 'myValue' | ||
}, | ||
fields: { | ||
myField: { | ||
touched: true | ||
} | ||
}, | ||
error: 'some global error', | ||
submitFailed: true | ||
} | ||
}); | ||
}); | ||
it('should unset global errors on stopSubmit with no errors', function () { | ||
var state = reducer(fromJS({ | ||
foo: { | ||
values: { | ||
myField: 'myValue' | ||
}, | ||
fields: { | ||
myField: { | ||
touched: true | ||
} | ||
}, | ||
submitting: true, | ||
@@ -255,2 +288,35 @@ error: 'Previous global error' | ||
it('should unset global errors on stopSubmit with field errors', function () { | ||
var state = reducer(fromJS({ | ||
foo: { | ||
values: { | ||
myField: 'myValue' | ||
}, | ||
fields: { | ||
myField: { | ||
touched: true | ||
} | ||
}, | ||
submitting: true, | ||
error: 'some global error' | ||
} | ||
}), stopSubmit('foo', { myField: 'some submit error' })); | ||
expect(state).toEqualMap({ | ||
foo: { | ||
values: { | ||
myField: 'myValue' | ||
}, | ||
submitErrors: { | ||
myField: 'some submit error' | ||
}, | ||
fields: { | ||
myField: { | ||
touched: true | ||
} | ||
}, | ||
submitFailed: true | ||
} | ||
}); | ||
}); | ||
it('should unset submitFailed and set submitSucceeded on stopSubmit with no errors', function () { | ||
@@ -257,0 +323,0 @@ var state = reducer(fromJS({ |
@@ -64,4 +64,4 @@ import { ARRAY_INSERT, ARRAY_MOVE, ARRAY_POP, ARRAY_PUSH, ARRAY_REMOVE, ARRAY_REMOVE_ALL, ARRAY_SHIFT, ARRAY_SPLICE, ARRAY_SWAP, ARRAY_UNSHIFT, AUTOFILL, 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 change = function change(form, field, value, touch) { | ||
return { type: CHANGE, meta: { form: form, field: field, touch: touch }, payload: value }; | ||
export var change = function change(form, field, value, touch, persistentSubmitErrors) { | ||
return { type: CHANGE, meta: { form: form, field: field, touch: touch, persistentSubmitErrors: persistentSubmitErrors }, payload: value }; | ||
}; | ||
@@ -68,0 +68,0 @@ |
@@ -18,16 +18,10 @@ 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 createConnectedField = function createConnectedField(_ref, _ref2, name) { | ||
var asyncValidate = _ref.asyncValidate; | ||
var blur = _ref.blur; | ||
var change = _ref.change; | ||
var focus = _ref.focus; | ||
var getFormState = _ref.getFormState; | ||
var initialValues = _ref.initialValues; | ||
var deepEqual = _ref2.deepEqual; | ||
var getIn = _ref2.getIn; | ||
var propsToNotUpdateFor = ['_reduxForm']; | ||
var createConnectedField = function createConnectedField(_ref) { | ||
var deepEqual = _ref.deepEqual; | ||
var getIn = _ref.getIn; | ||
var propInitialValue = initialValues && getIn(initialValues, name); | ||
var getSyncError = function getSyncError(syncErrors) { | ||
var getSyncError = function getSyncError(syncErrors, name) { | ||
var error = plain.getIn(syncErrors, name); | ||
@@ -51,3 +45,9 @@ // Because the error for this field might not be at a level in the error structure where | ||
value: function shouldComponentUpdate(nextProps) { | ||
return !deepEqual(this.props, nextProps); | ||
var _this2 = this; | ||
var nextPropsKeys = Object.keys(nextProps); | ||
var thisPropsKeys = Object.keys(this.props); | ||
return nextPropsKeys.length == thisPropsKeys.length && nextPropsKeys.some(function (prop) { | ||
return !~propsToNotUpdateFor.indexOf(prop) && !deepEqual(_this2.props[prop], nextProps[prop]); | ||
}); | ||
} | ||
@@ -75,6 +75,14 @@ }, { | ||
var withRef = _props.withRef; | ||
var name = _props.name; | ||
var _reduxForm = _props._reduxForm; | ||
var rest = _objectWithoutProperties(_props, ['component', 'withRef']); | ||
var rest = _objectWithoutProperties(_props, ['component', 'withRef', 'name', '_reduxForm']); | ||
var asyncValidate = _reduxForm.asyncValidate; | ||
var blur = _reduxForm.blur; | ||
var change = _reduxForm.change; | ||
var focus = _reduxForm.focus; | ||
var _createFieldProps = createFieldProps(getIn, name, _extends({}, rest, { | ||
name: name, | ||
blur: blur, | ||
@@ -113,8 +121,13 @@ change: change, | ||
var connector = connect(function (state, ownProps) { | ||
var name = ownProps.name; | ||
var _ownProps$_reduxForm = ownProps._reduxForm; | ||
var initialValues = _ownProps$_reduxForm.initialValues; | ||
var getFormState = _ownProps$_reduxForm.getFormState; | ||
var formState = getFormState(state); | ||
var initialState = getIn(formState, 'initial.' + name); | ||
var initial = initialState === undefined ? propInitialValue : initialState; | ||
var initial = initialState !== undefined ? initialState : initialValues && getIn(initialValues, name); | ||
var value = getIn(formState, 'values.' + name); | ||
var submitting = getIn(formState, 'submitting'); | ||
var syncError = getSyncError(getIn(formState, 'syncErrors')); | ||
var syncError = getSyncError(getIn(formState, 'syncErrors'), name); | ||
var pristine = value === initial; | ||
@@ -121,0 +134,0 @@ return { |
@@ -15,2 +15,3 @@ import _mapValues from 'lodash-es/mapValues'; | ||
import { connect } from 'react-redux'; | ||
import { bindActionCreators } from 'redux'; | ||
import createFieldArrayProps from './createFieldArrayProps'; | ||
@@ -20,29 +21,11 @@ | ||
var propsToNotUpdateFor = ['value']; | ||
var propsToNotUpdateFor = ['_reduxForm', 'value']; | ||
var createConnectedFieldArray = function createConnectedFieldArray(_ref, _ref2, name) { | ||
var arrayInsert = _ref.arrayInsert; | ||
var arrayMove = _ref.arrayMove; | ||
var arrayPop = _ref.arrayPop; | ||
var arrayPush = _ref.arrayPush; | ||
var arrayRemove = _ref.arrayRemove; | ||
var arrayRemoveAll = _ref.arrayRemoveAll; | ||
var arrayShift = _ref.arrayShift; | ||
var arraySplice = _ref.arraySplice; | ||
var arraySwap = _ref.arraySwap; | ||
var arrayUnshift = _ref.arrayUnshift; | ||
var asyncValidate = _ref.asyncValidate; | ||
var blur = _ref.blur; | ||
var change = _ref.change; | ||
var focus = _ref.focus; | ||
var getFormState = _ref.getFormState; | ||
var initialValues = _ref.initialValues; | ||
var deepEqual = _ref2.deepEqual; | ||
var getIn = _ref2.getIn; | ||
var size = _ref2.size; | ||
var createConnectedFieldArray = function createConnectedFieldArray(_ref) { | ||
var deepEqual = _ref.deepEqual; | ||
var getIn = _ref.getIn; | ||
var size = _ref.size; | ||
var propInitialValue = initialValues && getIn(initialValues, name); | ||
var getSyncError = function getSyncError(syncErrors) { | ||
var getSyncError = function getSyncError(syncErrors, name) { | ||
// For an array, the error can _ONLY_ be under _error. | ||
@@ -68,3 +51,5 @@ // This is why this getSyncError is not the same as the | ||
return Object.keys(nextProps).some(function (prop) { | ||
var nextPropsKeys = Object.keys(nextProps); | ||
var thisPropsKeys = Object.keys(this.props); | ||
return nextPropsKeys.length == thisPropsKeys.length && nextPropsKeys.some(function (prop) { | ||
// useful to debug rerenders | ||
@@ -85,7 +70,10 @@ // if (!plain.deepEqual(this.props[ prop ], nextProps[ prop ])) { | ||
value: function render() { | ||
/*eslint no-unused-vars: ["error", { "varsIgnorePattern": "^_reduxForm$" }]*/ | ||
var _props = this.props; | ||
var component = _props.component; | ||
var withRef = _props.withRef; | ||
var name = _props.name; | ||
var _reduxForm = _props._reduxForm; | ||
var rest = _objectWithoutProperties(_props, ['component', 'withRef']); | ||
var rest = _objectWithoutProperties(_props, ['component', 'withRef', 'name', '_reduxForm']); | ||
@@ -127,22 +115,13 @@ var props = createFieldArrayProps(getIn, name, rest); | ||
var actions = _mapValues({ | ||
arrayInsert: arrayInsert, | ||
arrayMove: arrayMove, | ||
arrayPop: arrayPop, | ||
arrayPush: arrayPush, | ||
arrayRemove: arrayRemove, | ||
arrayRemoveAll: arrayRemoveAll, | ||
arrayShift: arrayShift, | ||
arraySplice: arraySplice, | ||
arraySwap: arraySwap, | ||
arrayUnshift: arrayUnshift | ||
}, function (actionCreator) { | ||
return actionCreator.bind(null, name); | ||
}); | ||
var connector = connect(function (state) { | ||
var connector = connect(function (state, ownProps) { | ||
var name = ownProps.name; | ||
var _ownProps$_reduxForm = ownProps._reduxForm; | ||
var initialValues = _ownProps$_reduxForm.initialValues; | ||
var getFormState = _ownProps$_reduxForm.getFormState; | ||
var formState = getFormState(state); | ||
var initial = getIn(formState, 'initial.' + name) || propInitialValue; | ||
var initial = getIn(formState, 'initial.' + name) || initialValues && getIn(initialValues, name); | ||
var value = getIn(formState, 'values.' + name); | ||
var submitting = getIn(formState, 'submitting'); | ||
var syncError = getSyncError(getIn(formState, 'syncErrors')); | ||
var syncError = getSyncError(getIn(formState, 'syncErrors'), name); | ||
var pristine = deepEqual(value, initial); | ||
@@ -153,2 +132,3 @@ return { | ||
pristine: pristine, | ||
state: getIn(formState, 'fields.' + name), | ||
submitError: getIn(formState, 'submitErrors.' + name + '._error'), | ||
@@ -160,3 +140,31 @@ submitting: submitting, | ||
}; | ||
}, actions, undefined, { withRef: true }); | ||
}, function (dispatch, ownProps) { | ||
var name = ownProps.name; | ||
var _reduxForm = ownProps._reduxForm; | ||
var arrayInsert = _reduxForm.arrayInsert; | ||
var arrayMove = _reduxForm.arrayMove; | ||
var arrayPop = _reduxForm.arrayPop; | ||
var arrayPush = _reduxForm.arrayPush; | ||
var arrayRemove = _reduxForm.arrayRemove; | ||
var arrayRemoveAll = _reduxForm.arrayRemoveAll; | ||
var arrayShift = _reduxForm.arrayShift; | ||
var arraySplice = _reduxForm.arraySplice; | ||
var arraySwap = _reduxForm.arraySwap; | ||
var arrayUnshift = _reduxForm.arrayUnshift; | ||
return _mapValues({ | ||
arrayInsert: arrayInsert, | ||
arrayMove: arrayMove, | ||
arrayPop: arrayPop, | ||
arrayPush: arrayPush, | ||
arrayRemove: arrayRemove, | ||
arrayRemoveAll: arrayRemoveAll, | ||
arrayShift: arrayShift, | ||
arraySplice: arraySplice, | ||
arraySwap: arraySwap, | ||
arrayUnshift: arrayUnshift | ||
}, function (actionCreator) { | ||
return bindActionCreators(actionCreator.bind(null, name), dispatch); | ||
}); | ||
}, undefined, { withRef: true }); | ||
return connector(ConnectedFieldArray); | ||
@@ -163,0 +171,0 @@ }; |
@@ -18,13 +18,9 @@ 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 createConnectedFields = function createConnectedFields(_ref, _ref2, names) { | ||
var asyncValidate = _ref.asyncValidate; | ||
var blur = _ref.blur; | ||
var change = _ref.change; | ||
var focus = _ref.focus; | ||
var getFormState = _ref.getFormState; | ||
var initialValues = _ref.initialValues; | ||
var deepEqual = _ref2.deepEqual; | ||
var getIn = _ref2.getIn; | ||
var propsToNotUpdateFor = ['_reduxForm']; | ||
var createConnectedFields = function createConnectedFields(_ref) { | ||
var deepEqual = _ref.deepEqual; | ||
var getIn = _ref.getIn; | ||
var getSyncError = function getSyncError(syncErrors, name) { | ||
@@ -49,3 +45,9 @@ var error = plain.getIn(syncErrors, name); | ||
value: function shouldComponentUpdate(nextProps) { | ||
return !deepEqual(this.props, nextProps); | ||
var _this2 = this; | ||
var nextPropsKeys = Object.keys(nextProps); | ||
var thisPropsKeys = Object.keys(this.props); | ||
return nextPropsKeys.length == thisPropsKeys.length && nextPropsKeys.some(function (prop) { | ||
return !~propsToNotUpdateFor.indexOf(prop) && !deepEqual(_this2.props[prop], nextProps[prop]); | ||
}); | ||
} | ||
@@ -82,5 +84,11 @@ }, { | ||
var _fields = _props._fields; | ||
var _reduxForm = _props._reduxForm; | ||
var rest = _objectWithoutProperties(_props, ['component', 'withRef', '_fields']); | ||
var rest = _objectWithoutProperties(_props, ['component', 'withRef', '_fields', '_reduxForm']); | ||
var asyncValidate = _reduxForm.asyncValidate; | ||
var blur = _reduxForm.blur; | ||
var change = _reduxForm.change; | ||
var focus = _reduxForm.focus; | ||
var _Object$keys$reduce = Object.keys(_fields).reduce(function (accumulator, name) { | ||
@@ -125,2 +133,7 @@ var connectedProps = _fields[name]; | ||
var connector = connect(function (state, ownProps) { | ||
var names = ownProps.names; | ||
var _ownProps$_reduxForm = ownProps._reduxForm; | ||
var initialValues = _ownProps$_reduxForm.initialValues; | ||
var getFormState = _ownProps$_reduxForm.getFormState; | ||
var formState = getFormState(state); | ||
@@ -130,4 +143,3 @@ return { | ||
var initialState = getIn(formState, 'initial.' + name); | ||
var propInitialValue = initialValues && getIn(initialValues, name); | ||
var initial = initialState === undefined ? propInitialValue : initialState; | ||
var initial = initialState !== undefined ? initialState : initialValues && getIn(initialValues, name); | ||
var value = getIn(formState, 'values.' + name); | ||
@@ -134,0 +146,0 @@ var syncError = getSyncError(getIn(formState, 'syncErrors'), name); |
@@ -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 submitError = _ref.submitError; | ||
var state = _ref.state; | ||
var submitFailed = _ref.submitFailed; | ||
@@ -28,3 +29,3 @@ var submitting = _ref.submitting; | ||
var rest = _objectWithoutProperties(_ref, ["arrayInsert", "arrayMove", "arrayPop", "arrayPush", "arrayRemove", "arrayRemoveAll", "arrayShift", "arraySplice", "arraySwap", "arrayUnshift", "asyncError", "dirty", "length", "pristine", "submitError", "submitFailed", "submitting", "syncError", "value", "props"]); | ||
var rest = _objectWithoutProperties(_ref, ['arrayInsert', 'arrayMove', 'arrayPop', 'arrayPush', 'arrayRemove', 'arrayRemoveAll', 'arrayShift', 'arraySplice', 'arraySwap', 'arrayUnshift', 'asyncError', 'dirty', 'length', 'pristine', 'submitError', 'state', 'submitFailed', 'submitting', 'syncError', 'value', 'props']); | ||
@@ -37,3 +38,3 @@ var error = syncError || asyncError || submitError; | ||
return (value || []).forEach(function (item, index) { | ||
return callback(name + "[" + index + "]", index); | ||
return callback(name + '[' + index + ']', index); | ||
}); | ||
@@ -45,3 +46,3 @@ }, | ||
return (value || []).map(function (item, index) { | ||
return callback(name + "[" + index + "]", index); | ||
return callback(name + '[' + index + ']', index); | ||
}); | ||
@@ -57,3 +58,3 @@ }, | ||
return (value || []).reduce(function (accumulator, item, index) { | ||
return callback(accumulator, name + "[" + index + "]", index); | ||
return callback(accumulator, name + '[' + index + ']', index); | ||
}, initial); | ||
@@ -76,2 +77,3 @@ }, | ||
submitting: submitting, | ||
touched: !!(state && getIn(state, 'touched')), | ||
valid: !error | ||
@@ -78,0 +80,0 @@ } |
@@ -96,3 +96,3 @@ import _noop from 'lodash-es/noop'; | ||
}, _value), | ||
meta: { | ||
meta: _extends({}, state, { | ||
active: !!(state && getIn(state, 'active')), | ||
@@ -110,3 +110,3 @@ asyncValidating: asyncValidating, | ||
visited: !!(state && getIn(state, 'visited')) | ||
}, | ||
}), | ||
custom: _extends({}, custom, props) | ||
@@ -113,0 +113,0 @@ }; |
@@ -21,2 +21,8 @@ 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 ConnectedField = createConnectedField({ | ||
deepEqual: deepEqual, | ||
getIn: getIn | ||
}); | ||
var Field = function (_Component) { | ||
@@ -33,6 +39,3 @@ _inherits(Field, _Component); | ||
} | ||
_this.ConnectedField = createConnectedField(context._reduxForm, { | ||
deepEqual: deepEqual, | ||
getIn: getIn | ||
}, props.name); | ||
_this.normalize = _this.normalize.bind(_this); | ||
@@ -56,4 +59,2 @@ return _this; | ||
if (this.props.name !== nextProps.name) { | ||
// name changed, regenerate connected field | ||
this.ConnectedField = createConnectedField(this.context._reduxForm, { deepEqual: deepEqual, getIn: getIn }, nextProps.name); | ||
// unregister old name | ||
@@ -92,4 +93,5 @@ this.context._reduxForm.unregister(this.props.name); | ||
value: function render() { | ||
return createElement(this.ConnectedField, _extends({}, this.props, { | ||
return createElement(ConnectedField, _extends({}, this.props, { | ||
normalize: this.normalize, | ||
_reduxForm: this.context._reduxForm, | ||
ref: 'connected' | ||
@@ -96,0 +98,0 @@ })); |
@@ -21,2 +21,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; }; | ||
var ConnectedFieldArray = createConnectedFieldArray({ deepEqual: deepEqual, getIn: getIn, size: size }); | ||
var FieldArray = function (_Component) { | ||
@@ -33,3 +36,2 @@ _inherits(FieldArray, _Component); | ||
} | ||
_this.ConnectedFieldArray = createConnectedFieldArray(context._reduxForm, { deepEqual: deepEqual, getIn: getIn, size: size }, props.name); | ||
return _this; | ||
@@ -52,8 +54,6 @@ } | ||
if (this.props.name !== nextProps.name) { | ||
// name changed, regenerate connected field | ||
this.ConnectedFieldArray = createConnectedFieldArray(this.context._reduxForm, { | ||
deepEqual: deepEqual, | ||
getIn: getIn, | ||
size: size | ||
}, nextProps.name); | ||
// unregister old name | ||
this.context._reduxForm.unregister(this.props.name); | ||
// register new name | ||
this.context._reduxForm.register(nextProps.name, 'FieldArray'); | ||
} | ||
@@ -75,4 +75,5 @@ } | ||
value: function render() { | ||
return createElement(this.ConnectedFieldArray, _extends({}, this.props, { | ||
return createElement(ConnectedFieldArray, _extends({}, this.props, { | ||
syncError: this.syncError, | ||
_reduxForm: this.context._reduxForm, | ||
ref: 'connected' | ||
@@ -79,0 +80,0 @@ })); |
@@ -30,2 +30,8 @@ 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 ConnectedFields = createConnectedFields({ | ||
deepEqual: deepEqual, | ||
getIn: getIn | ||
}); | ||
var Fields = function (_Component) { | ||
@@ -42,6 +48,2 @@ _inherits(Fields, _Component); | ||
} | ||
_this.ConnectedFields = createConnectedFields(context._reduxForm, { | ||
deepEqual: deepEqual, | ||
getIn: getIn | ||
}, _this.names); | ||
return _this; | ||
@@ -71,5 +73,17 @@ } | ||
value: function componentWillReceiveProps(nextProps) { | ||
var _this2 = this; | ||
if (!plain.deepEqual(this.props.names, nextProps.names)) { | ||
// names changed, regenerate connected field | ||
this.ConnectedFields = createConnectedFields(this.context._reduxForm, { deepEqual: deepEqual, getIn: getIn }, nextProps.names); | ||
(function () { | ||
var _context$_reduxForm = _this2.context._reduxForm; | ||
var register = _context$_reduxForm.register; | ||
var unregister = _context$_reduxForm.unregister; | ||
// unregister old name | ||
_this2.props.names.forEach(unregister); | ||
// register new name | ||
nextProps.names.forEach(function (name) { | ||
return register(name, 'Field'); | ||
}); | ||
})(); | ||
} | ||
@@ -91,3 +105,4 @@ } | ||
value: function render() { | ||
return createElement(this.ConnectedFields, _extends({}, this.props, { | ||
return createElement(ConnectedFields, _extends({}, this.props, { | ||
_reduxForm: this.context._reduxForm, | ||
ref: 'connected' | ||
@@ -94,0 +109,0 @@ })); |
@@ -17,2 +17,3 @@ 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 values = props.values; | ||
var persistentSubmitErrors = props.persistentSubmitErrors; | ||
@@ -22,3 +23,8 @@ | ||
if (valid) { | ||
// XXX: Always submitting when persistentSubmitErrors is enabled ignores sync errors. | ||
// It would be better to check whether the form as any other errors except submit errors. | ||
// This would either require changing the meaning of `valid` (maybe breaking change), | ||
// having a more complex conditional in here, or executing sync validation in here | ||
// the same way as async validation is executed. | ||
if (valid || persistentSubmitErrors) { | ||
var doSubmit = function doSubmit() { | ||
@@ -25,0 +31,0 @@ var result = void 0; |
@@ -159,2 +159,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 touch = _ref13$meta.touch; | ||
var persistentSubmitErrors = _ref13$meta.persistentSubmitErrors; | ||
var payload = _ref13.payload; | ||
@@ -170,5 +171,9 @@ | ||
result = deleteInWithCleanUp(result, 'asyncErrors.' + field); | ||
result = deleteInWithCleanUp(result, 'submitErrors.' + field); | ||
if (!persistentSubmitErrors) { | ||
result = deleteInWithCleanUp(result, 'submitErrors.' + field); | ||
} | ||
result = deleteInWithCleanUp(result, 'fields.' + field + '.autofilled'); | ||
result = deleteInWithCleanUp(result, 'error'); | ||
if (!persistentSubmitErrors) { | ||
result = deleteInWithCleanUp(result, 'error'); | ||
} | ||
if (touch) { | ||
@@ -302,2 +307,4 @@ result = setIn(result, 'fields.' + field + '.touched', true); | ||
result = setIn(result, 'error', _error); | ||
} else { | ||
result = deleteIn(result, 'error'); | ||
} | ||
@@ -334,3 +341,2 @@ if (Object.keys(fieldErrors).length) { | ||
result = setIn(result, 'submitSucceeded', true); | ||
result = deleteIn(result, 'submitting'); | ||
return result; | ||
@@ -337,0 +343,0 @@ }), _defineProperty(_behaviors, TOUCH, function (state, _ref21) { |
@@ -95,2 +95,3 @@ import _mapValues from 'lodash-es/mapValues'; | ||
touchOnChange: false, | ||
persistentSubmitErrors: false, | ||
destroyOnUnmount: true, | ||
@@ -330,5 +331,4 @@ shouldAsyncValidate: defaultShouldAsyncValidate, | ||
this.submitPromise = promise; | ||
return promise.then(this.submitCompleted, function (err) { | ||
return promise.then(this.submitCompleted, function () { | ||
_this5.submitCompleted(); | ||
return Promise.reject(err); | ||
}); | ||
@@ -415,2 +415,3 @@ } | ||
var touchOnChange = _props5.touchOnChange; | ||
var persistentSubmitErrors = _props5.persistentSubmitErrors; | ||
var syncErrors = _props5.syncErrors; | ||
@@ -423,3 +424,3 @@ var unregisterField = _props5.unregisterField; | ||
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']); | ||
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', 'persistentSubmitErrors', 'syncErrors', 'unregisterField', 'untouch', 'updateSyncErrors', 'valid', 'values']); | ||
/* eslint-enable no-unused-vars */ | ||
@@ -480,2 +481,3 @@ | ||
touchOnChange: PropTypes.bool, | ||
persistentSubmitErrors: PropTypes.bool, | ||
registeredFields: PropTypes.any | ||
@@ -532,3 +534,3 @@ }; | ||
var boundChange = function boundChange(field, value) { | ||
return change(initialProps.form, field, value, !!initialProps.touchOnChange); | ||
return change(initialProps.form, field, value, !!initialProps.touchOnChange, !!initialProps.persistentSubmitErrors); | ||
}; | ||
@@ -552,5 +554,6 @@ var boundFocus = bindForm(focus); | ||
var computedActions = _extends({}, connectedFormACs, boundArrayACs, { | ||
var computedActions = _extends({}, connectedFormACs, boundArrayACs, bindActionCreators({ | ||
blur: boundBlur, | ||
change: boundChange, | ||
change: boundChange | ||
}, dispatch), { | ||
array: connectedArrayACs, | ||
@@ -557,0 +560,0 @@ focus: boundFocus, |
@@ -262,2 +262,14 @@ import expect from 'expect'; | ||
}); | ||
it('should treat false and undefined as equal', function () { | ||
testBothWays(fromJS({ | ||
a: { | ||
b: false | ||
} | ||
}), fromJS({ | ||
a: { | ||
b: undefined | ||
} | ||
}), true); | ||
}); | ||
}); |
@@ -6,4 +6,3 @@ import _isEqualWith from 'lodash-es/isEqualWith'; | ||
if (obj == other) return true; | ||
if (obj == null && other === '') return true; | ||
if (obj === '' && other == null) return true; | ||
if ((obj == null || obj === '' || obj === false) && (other == null || other === '' || other === false)) return true; | ||
@@ -10,0 +9,0 @@ if (Iterable.isIterable(obj) && Iterable.isIterable(other)) { |
@@ -5,2 +5,3 @@ import _toPath from 'lodash-es/toPath'; | ||
import deepEqual from './deepEqual'; | ||
import setIn from './setIn'; | ||
import splice from './splice'; | ||
@@ -15,5 +16,3 @@ import plainGetIn from '../plain/getIn'; | ||
}, | ||
setIn: function setIn(state, field, value) { | ||
return state.setIn(_toPath(field), value); | ||
}, | ||
setIn: setIn, | ||
deepEqual: deepEqual, | ||
@@ -20,0 +19,0 @@ deleteIn: function deleteIn(state, field) { |
@@ -174,2 +174,14 @@ import expect from 'expect'; | ||
}); | ||
it('should treat false and undefined as equal', function () { | ||
testBothWays({ | ||
a: { | ||
b: false | ||
} | ||
}, { | ||
a: { | ||
b: undefined | ||
} | ||
}, true); | ||
}); | ||
}); |
@@ -6,4 +6,4 @@ import _isEqualWith from 'lodash-es/isEqualWith'; | ||
if (obj == other) return true; | ||
if (obj == null && other === '') return true; | ||
if (obj === '' && other == null) return true; | ||
if ((obj == null || obj === '' || obj === false) && (other == null || other === '' || other === false)) return true; | ||
if (obj && other && obj._error !== other._error) return false; | ||
@@ -10,0 +10,0 @@ }; |
import _toPath from 'lodash-es/toPath'; | ||
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 getInWithPath = function getInWithPath(state, first) { | ||
for (var _len = arguments.length, rest = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { | ||
rest[_key - 2] = arguments[_key]; | ||
} | ||
if (!state) { | ||
return state; | ||
} | ||
var next = state[first]; | ||
return rest.length ? getInWithPath.apply(undefined, [next].concat(rest)) : next; | ||
}; | ||
var getIn = function getIn(state, field) { | ||
@@ -24,24 +11,11 @@ if (!state) { | ||
var length = path.length; | ||
if (length > 3) { | ||
return getInWithPath.apply(undefined, [state].concat(_toConsumableArray(path))); | ||
if (!length) { | ||
return undefined; | ||
} | ||
var result = state; | ||
if (!length || !result) { | ||
return undefined; | ||
for (var i = 0; i < length && !!result; ++i) { | ||
result = result[path[i]]; | ||
} | ||
result = result[path[0]]; | ||
if (length === 1 || !result) { | ||
return result; | ||
} | ||
result = result[path[1]]; | ||
if (length === 2 || !result) { | ||
return result; | ||
} | ||
result = result[path[2]]; | ||
return result; | ||
@@ -48,0 +22,0 @@ }; |
@@ -33,16 +33,10 @@ 'use strict'; | ||
var createConnectedField = function createConnectedField(_ref, _ref2, name) { | ||
var asyncValidate = _ref.asyncValidate; | ||
var blur = _ref.blur; | ||
var change = _ref.change; | ||
var focus = _ref.focus; | ||
var getFormState = _ref.getFormState; | ||
var initialValues = _ref.initialValues; | ||
var deepEqual = _ref2.deepEqual; | ||
var getIn = _ref2.getIn; | ||
var propsToNotUpdateFor = ['_reduxForm']; | ||
var createConnectedField = function createConnectedField(_ref) { | ||
var deepEqual = _ref.deepEqual; | ||
var getIn = _ref.getIn; | ||
var propInitialValue = initialValues && getIn(initialValues, name); | ||
var getSyncError = function getSyncError(syncErrors) { | ||
var getSyncError = function getSyncError(syncErrors, name) { | ||
var error = _plain2.default.getIn(syncErrors, name); | ||
@@ -66,3 +60,9 @@ // Because the error for this field might not be at a level in the error structure where | ||
value: function shouldComponentUpdate(nextProps) { | ||
return !deepEqual(this.props, nextProps); | ||
var _this2 = this; | ||
var nextPropsKeys = Object.keys(nextProps); | ||
var thisPropsKeys = Object.keys(this.props); | ||
return nextPropsKeys.length == thisPropsKeys.length && nextPropsKeys.some(function (prop) { | ||
return !~propsToNotUpdateFor.indexOf(prop) && !deepEqual(_this2.props[prop], nextProps[prop]); | ||
}); | ||
} | ||
@@ -90,6 +90,14 @@ }, { | ||
var withRef = _props.withRef; | ||
var name = _props.name; | ||
var _reduxForm = _props._reduxForm; | ||
var rest = _objectWithoutProperties(_props, ['component', 'withRef']); | ||
var rest = _objectWithoutProperties(_props, ['component', 'withRef', 'name', '_reduxForm']); | ||
var asyncValidate = _reduxForm.asyncValidate; | ||
var blur = _reduxForm.blur; | ||
var change = _reduxForm.change; | ||
var focus = _reduxForm.focus; | ||
var _createFieldProps = (0, _createFieldProps3.default)(getIn, name, _extends({}, rest, { | ||
name: name, | ||
blur: blur, | ||
@@ -128,8 +136,13 @@ change: change, | ||
var connector = (0, _reactRedux.connect)(function (state, ownProps) { | ||
var name = ownProps.name; | ||
var _ownProps$_reduxForm = ownProps._reduxForm; | ||
var initialValues = _ownProps$_reduxForm.initialValues; | ||
var getFormState = _ownProps$_reduxForm.getFormState; | ||
var formState = getFormState(state); | ||
var initialState = getIn(formState, 'initial.' + name); | ||
var initial = initialState === undefined ? propInitialValue : initialState; | ||
var initial = initialState !== undefined ? initialState : initialValues && getIn(initialValues, name); | ||
var value = getIn(formState, 'values.' + name); | ||
var submitting = getIn(formState, 'submitting'); | ||
var syncError = getSyncError(getIn(formState, 'syncErrors')); | ||
var syncError = getSyncError(getIn(formState, 'syncErrors'), name); | ||
var pristine = value === initial; | ||
@@ -136,0 +149,0 @@ return { |
@@ -17,2 +17,4 @@ 'use strict'; | ||
var _redux = require('redux'); | ||
var _createFieldArrayProps = require('./createFieldArrayProps'); | ||
@@ -36,29 +38,11 @@ | ||
var propsToNotUpdateFor = ['value']; | ||
var propsToNotUpdateFor = ['_reduxForm', 'value']; | ||
var createConnectedFieldArray = function createConnectedFieldArray(_ref, _ref2, name) { | ||
var arrayInsert = _ref.arrayInsert; | ||
var arrayMove = _ref.arrayMove; | ||
var arrayPop = _ref.arrayPop; | ||
var arrayPush = _ref.arrayPush; | ||
var arrayRemove = _ref.arrayRemove; | ||
var arrayRemoveAll = _ref.arrayRemoveAll; | ||
var arrayShift = _ref.arrayShift; | ||
var arraySplice = _ref.arraySplice; | ||
var arraySwap = _ref.arraySwap; | ||
var arrayUnshift = _ref.arrayUnshift; | ||
var asyncValidate = _ref.asyncValidate; | ||
var blur = _ref.blur; | ||
var change = _ref.change; | ||
var focus = _ref.focus; | ||
var getFormState = _ref.getFormState; | ||
var initialValues = _ref.initialValues; | ||
var deepEqual = _ref2.deepEqual; | ||
var getIn = _ref2.getIn; | ||
var size = _ref2.size; | ||
var createConnectedFieldArray = function createConnectedFieldArray(_ref) { | ||
var deepEqual = _ref.deepEqual; | ||
var getIn = _ref.getIn; | ||
var size = _ref.size; | ||
var propInitialValue = initialValues && getIn(initialValues, name); | ||
var getSyncError = function getSyncError(syncErrors) { | ||
var getSyncError = function getSyncError(syncErrors, name) { | ||
// For an array, the error can _ONLY_ be under _error. | ||
@@ -84,3 +68,5 @@ // This is why this getSyncError is not the same as the | ||
return Object.keys(nextProps).some(function (prop) { | ||
var nextPropsKeys = Object.keys(nextProps); | ||
var thisPropsKeys = Object.keys(this.props); | ||
return nextPropsKeys.length == thisPropsKeys.length && nextPropsKeys.some(function (prop) { | ||
// useful to debug rerenders | ||
@@ -101,7 +87,10 @@ // if (!plain.deepEqual(this.props[ prop ], nextProps[ prop ])) { | ||
value: function render() { | ||
/*eslint no-unused-vars: ["error", { "varsIgnorePattern": "^_reduxForm$" }]*/ | ||
var _props = this.props; | ||
var component = _props.component; | ||
var withRef = _props.withRef; | ||
var name = _props.name; | ||
var _reduxForm = _props._reduxForm; | ||
var rest = _objectWithoutProperties(_props, ['component', 'withRef']); | ||
var rest = _objectWithoutProperties(_props, ['component', 'withRef', 'name', '_reduxForm']); | ||
@@ -143,22 +132,13 @@ var props = (0, _createFieldArrayProps2.default)(getIn, name, rest); | ||
var actions = (0, _mapValues3.default)({ | ||
arrayInsert: arrayInsert, | ||
arrayMove: arrayMove, | ||
arrayPop: arrayPop, | ||
arrayPush: arrayPush, | ||
arrayRemove: arrayRemove, | ||
arrayRemoveAll: arrayRemoveAll, | ||
arrayShift: arrayShift, | ||
arraySplice: arraySplice, | ||
arraySwap: arraySwap, | ||
arrayUnshift: arrayUnshift | ||
}, function (actionCreator) { | ||
return actionCreator.bind(null, name); | ||
}); | ||
var connector = (0, _reactRedux.connect)(function (state) { | ||
var connector = (0, _reactRedux.connect)(function (state, ownProps) { | ||
var name = ownProps.name; | ||
var _ownProps$_reduxForm = ownProps._reduxForm; | ||
var initialValues = _ownProps$_reduxForm.initialValues; | ||
var getFormState = _ownProps$_reduxForm.getFormState; | ||
var formState = getFormState(state); | ||
var initial = getIn(formState, 'initial.' + name) || propInitialValue; | ||
var initial = getIn(formState, 'initial.' + name) || initialValues && getIn(initialValues, name); | ||
var value = getIn(formState, 'values.' + name); | ||
var submitting = getIn(formState, 'submitting'); | ||
var syncError = getSyncError(getIn(formState, 'syncErrors')); | ||
var syncError = getSyncError(getIn(formState, 'syncErrors'), name); | ||
var pristine = deepEqual(value, initial); | ||
@@ -169,2 +149,3 @@ return { | ||
pristine: pristine, | ||
state: getIn(formState, 'fields.' + name), | ||
submitError: getIn(formState, 'submitErrors.' + name + '._error'), | ||
@@ -176,3 +157,31 @@ submitting: submitting, | ||
}; | ||
}, actions, undefined, { withRef: true }); | ||
}, function (dispatch, ownProps) { | ||
var name = ownProps.name; | ||
var _reduxForm = ownProps._reduxForm; | ||
var arrayInsert = _reduxForm.arrayInsert; | ||
var arrayMove = _reduxForm.arrayMove; | ||
var arrayPop = _reduxForm.arrayPop; | ||
var arrayPush = _reduxForm.arrayPush; | ||
var arrayRemove = _reduxForm.arrayRemove; | ||
var arrayRemoveAll = _reduxForm.arrayRemoveAll; | ||
var arrayShift = _reduxForm.arrayShift; | ||
var arraySplice = _reduxForm.arraySplice; | ||
var arraySwap = _reduxForm.arraySwap; | ||
var arrayUnshift = _reduxForm.arrayUnshift; | ||
return (0, _mapValues3.default)({ | ||
arrayInsert: arrayInsert, | ||
arrayMove: arrayMove, | ||
arrayPop: arrayPop, | ||
arrayPush: arrayPush, | ||
arrayRemove: arrayRemove, | ||
arrayRemoveAll: arrayRemoveAll, | ||
arrayShift: arrayShift, | ||
arraySplice: arraySplice, | ||
arraySwap: arraySwap, | ||
arrayUnshift: arrayUnshift | ||
}, function (actionCreator) { | ||
return (0, _redux.bindActionCreators)(actionCreator.bind(null, name), dispatch); | ||
}); | ||
}, undefined, { withRef: true }); | ||
return connector(ConnectedFieldArray); | ||
@@ -179,0 +188,0 @@ }; |
@@ -33,13 +33,9 @@ 'use strict'; | ||
var createConnectedFields = function createConnectedFields(_ref, _ref2, names) { | ||
var asyncValidate = _ref.asyncValidate; | ||
var blur = _ref.blur; | ||
var change = _ref.change; | ||
var focus = _ref.focus; | ||
var getFormState = _ref.getFormState; | ||
var initialValues = _ref.initialValues; | ||
var deepEqual = _ref2.deepEqual; | ||
var getIn = _ref2.getIn; | ||
var propsToNotUpdateFor = ['_reduxForm']; | ||
var createConnectedFields = function createConnectedFields(_ref) { | ||
var deepEqual = _ref.deepEqual; | ||
var getIn = _ref.getIn; | ||
var getSyncError = function getSyncError(syncErrors, name) { | ||
@@ -64,3 +60,9 @@ var error = _plain2.default.getIn(syncErrors, name); | ||
value: function shouldComponentUpdate(nextProps) { | ||
return !deepEqual(this.props, nextProps); | ||
var _this2 = this; | ||
var nextPropsKeys = Object.keys(nextProps); | ||
var thisPropsKeys = Object.keys(this.props); | ||
return nextPropsKeys.length == thisPropsKeys.length && nextPropsKeys.some(function (prop) { | ||
return !~propsToNotUpdateFor.indexOf(prop) && !deepEqual(_this2.props[prop], nextProps[prop]); | ||
}); | ||
} | ||
@@ -97,5 +99,11 @@ }, { | ||
var _fields = _props._fields; | ||
var _reduxForm = _props._reduxForm; | ||
var rest = _objectWithoutProperties(_props, ['component', 'withRef', '_fields']); | ||
var rest = _objectWithoutProperties(_props, ['component', 'withRef', '_fields', '_reduxForm']); | ||
var asyncValidate = _reduxForm.asyncValidate; | ||
var blur = _reduxForm.blur; | ||
var change = _reduxForm.change; | ||
var focus = _reduxForm.focus; | ||
var _Object$keys$reduce = Object.keys(_fields).reduce(function (accumulator, name) { | ||
@@ -140,2 +148,7 @@ var connectedProps = _fields[name]; | ||
var connector = (0, _reactRedux.connect)(function (state, ownProps) { | ||
var names = ownProps.names; | ||
var _ownProps$_reduxForm = ownProps._reduxForm; | ||
var initialValues = _ownProps$_reduxForm.initialValues; | ||
var getFormState = _ownProps$_reduxForm.getFormState; | ||
var formState = getFormState(state); | ||
@@ -145,4 +158,3 @@ return { | ||
var initialState = getIn(formState, 'initial.' + name); | ||
var propInitialValue = initialValues && getIn(initialValues, name); | ||
var initial = initialState === undefined ? propInitialValue : initialState; | ||
var initial = initialState !== undefined ? initialState : initialValues && getIn(initialValues, name); | ||
var value = getIn(formState, 'values.' + name); | ||
@@ -149,0 +161,0 @@ var syncError = getSyncError(getIn(formState, 'syncErrors'), name); |
@@ -38,2 +38,8 @@ 'use strict'; | ||
var ConnectedField = (0, _ConnectedField2.default)({ | ||
deepEqual: deepEqual, | ||
getIn: getIn | ||
}); | ||
var Field = function (_Component) { | ||
@@ -50,6 +56,3 @@ _inherits(Field, _Component); | ||
} | ||
_this.ConnectedField = (0, _ConnectedField2.default)(context._reduxForm, { | ||
deepEqual: deepEqual, | ||
getIn: getIn | ||
}, props.name); | ||
_this.normalize = _this.normalize.bind(_this); | ||
@@ -73,4 +76,2 @@ return _this; | ||
if (this.props.name !== nextProps.name) { | ||
// name changed, regenerate connected field | ||
this.ConnectedField = (0, _ConnectedField2.default)(this.context._reduxForm, { deepEqual: deepEqual, getIn: getIn }, nextProps.name); | ||
// unregister old name | ||
@@ -109,4 +110,5 @@ this.context._reduxForm.unregister(this.props.name); | ||
value: function render() { | ||
return (0, _react.createElement)(this.ConnectedField, _extends({}, this.props, { | ||
return (0, _react.createElement)(ConnectedField, _extends({}, this.props, { | ||
normalize: this.normalize, | ||
_reduxForm: this.context._reduxForm, | ||
ref: 'connected' | ||
@@ -113,0 +115,0 @@ })); |
@@ -38,2 +38,5 @@ 'use strict'; | ||
var ConnectedFieldArray = (0, _ConnectedFieldArray2.default)({ deepEqual: deepEqual, getIn: getIn, size: size }); | ||
var FieldArray = function (_Component) { | ||
@@ -50,3 +53,2 @@ _inherits(FieldArray, _Component); | ||
} | ||
_this.ConnectedFieldArray = (0, _ConnectedFieldArray2.default)(context._reduxForm, { deepEqual: deepEqual, getIn: getIn, size: size }, props.name); | ||
return _this; | ||
@@ -69,8 +71,6 @@ } | ||
if (this.props.name !== nextProps.name) { | ||
// name changed, regenerate connected field | ||
this.ConnectedFieldArray = (0, _ConnectedFieldArray2.default)(this.context._reduxForm, { | ||
deepEqual: deepEqual, | ||
getIn: getIn, | ||
size: size | ||
}, nextProps.name); | ||
// unregister old name | ||
this.context._reduxForm.unregister(this.props.name); | ||
// register new name | ||
this.context._reduxForm.register(nextProps.name, 'FieldArray'); | ||
} | ||
@@ -92,4 +92,5 @@ } | ||
value: function render() { | ||
return (0, _react.createElement)(this.ConnectedFieldArray, _extends({}, this.props, { | ||
return (0, _react.createElement)(ConnectedFieldArray, _extends({}, this.props, { | ||
syncError: this.syncError, | ||
_reduxForm: this.context._reduxForm, | ||
ref: 'connected' | ||
@@ -96,0 +97,0 @@ })); |
{ | ||
"name": "redux-form", | ||
"version": "6.0.2", | ||
"version": "6.0.3", | ||
"description": "A higher order component decorator for forms using Redux and React", | ||
@@ -19,3 +19,15 @@ "main": "./lib/index.js", | ||
"lint": "eslint src", | ||
"example:simple": "node examples/simple/server.js", | ||
"example": "npm --prefix ./examples/$form install && npm --prefix ./examples/$form start", | ||
"example:asyncValidation": "form=asyncValidation npm run example", | ||
"example:fieldArrays": "form=fieldArrays npm run example", | ||
"example:immutable": "form=immutable npm run example", | ||
"example:initializeFromState": "form=initializeFromState npm run example", | ||
"example:material-ui": "form=material-ui npm run example", | ||
"example:normalizing": "form=normalizing npm run example", | ||
"example:react-widgets": "form=react-widgets npm run example", | ||
"example:selectingFormValues": "form=selectingFormValues npm run example", | ||
"example:simple": "form=simple npm run example", | ||
"example:submitValidation": "form=submitValidation npm run example", | ||
"example:syncValidation": "form=syncValidation npm run example", | ||
"example:wizard": "form=wizard npm run example", | ||
"prepublish": "npm run test && npm run clean && npm run build", | ||
@@ -46,3 +58,3 @@ "test": "mocha --compilers js:babel-register --recursive --recursive \"src/**/__tests__/*\" --require src/__tests__/setup.js", | ||
"deep-equal": "^1.0.1", | ||
"es6-error": "^3.0.0", | ||
"es6-error": "^3.1.0", | ||
"hoist-non-react-statics": "^1.0.5", | ||
@@ -49,0 +61,0 @@ "invariant": "^2.2.1", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
0
34
773532
140
19374
Updatedes6-error@^3.1.0