Skip to content

Instantly share code, notes, and snippets.

@anu1097
Created May 9, 2018 18:30
Show Gist options
  • Save anu1097/4b9d29c5d830bcbc9a04ba484a4225cb to your computer and use it in GitHub Desktop.
Save anu1097/4b9d29c5d830bcbc9a04ba484a4225cb to your computer and use it in GitHub Desktop.
var createIsPristine = function createIsPristine(_ref) {
var deepEqual = _ref.deepEqual,
empty = _ref.empty,
getIn = _ref.getIn;
return function (form, getFormState) {
return function (state) {
for (var _len = arguments.length, fields = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
fields[_key - 1] = arguments[_key];
}
var nonNullGetFormState = getFormState || function (state) {
return getIn(state, 'form');
};
var formState = nonNullGetFormState(state);
if (fields && fields.length) {
return fields.every(function (field) {
var fieldInitial = getIn(formState, form + '.initial.' + field);
var fieldValue = getIn(formState, form + '.values.' + field);
return deepEqual(fieldInitial, fieldValue);
});
}
var initial = getIn(formState, form + '.initial') || empty;
var values = getIn(formState, form + '.values') || initial;
return deepEqual(initial, values);
};
};
};
export default createIsPristine;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment