redux-form
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -83,4 +83,4 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
exports.CHANGE = CHANGE; | ||
var VALIDATE = 'REDUX_FORM_VALIDATE'; | ||
exports.VALIDATE = VALIDATE; | ||
var SHOW_ALL = 'REDUX_FORM_SHOW_ALL'; | ||
exports.SHOW_ALL = SHOW_ALL; | ||
var RESET = 'REDUX_FORM_RESET'; | ||
@@ -137,3 +137,3 @@ exports.RESET = RESET; | ||
exports.change = change; | ||
exports.validate = validate; | ||
exports.showAll = showAll; | ||
exports.reset = reset; | ||
@@ -152,5 +152,5 @@ | ||
function validate(form) { | ||
function showAll(form) { | ||
return { | ||
type: _actionTypes.VALIDATE, | ||
type: _actionTypes.SHOW_ALL, | ||
form: form | ||
@@ -188,6 +188,2 @@ }; | ||
* }, | ||
* errors: { | ||
* field1: 'error for field1', | ||
* field2: 'error for field2' | ||
* }, | ||
* visited: { | ||
@@ -202,4 +198,3 @@ * field1: true, | ||
* @param name the name of the "state slice" where the data is stored | ||
* @param fields an array of field names, used when validating all values | ||
* @param validate a validation function that takes all the data and returns all the errors | ||
* @param fields an array of field names, used when showing all values | ||
* @param initialData initial data to populate the state with | ||
@@ -210,7 +205,7 @@ * @returns {Function} a form reducer | ||
function createFormReducer(name, fields) { | ||
var validate = arguments.length <= 2 || arguments[2] === undefined ? function () {} : arguments[2]; | ||
var initialData = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; | ||
var initialData = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
var initialState = { data: initialData, visited: {} }; | ||
return function () { | ||
var state = arguments.length <= 0 || arguments[0] === undefined ? { data: initialData, errors: {}, visited: {} } : arguments[0]; | ||
var state = arguments.length <= 0 || arguments[0] === undefined ? initialState : arguments[0]; | ||
@@ -229,8 +224,6 @@ var _extends2, _extends3; | ||
data: data, | ||
errors: validate(data), | ||
visited: _extends({}, state.visited, (_extends3 = {}, _extends3[action.field] = true, _extends3)) | ||
}); | ||
case _actionTypes.VALIDATE: | ||
var errors = validate(state.data); | ||
var visited = state.visited; | ||
case _actionTypes.SHOW_ALL: | ||
var visited = {}; | ||
fields.forEach(function (key) { | ||
@@ -240,11 +233,6 @@ return visited[key] = true; | ||
return _extends({}, state, { | ||
errors: errors, | ||
visited: visited | ||
}); | ||
case _actionTypes.RESET: | ||
return { | ||
data: initialData, | ||
errors: {}, | ||
visited: {} | ||
}; | ||
return initialState; | ||
default: | ||
@@ -292,6 +280,6 @@ return state; | ||
* @param sliceName The key in the state corresponding to the data in this form | ||
* @param changeCreator An action creator to accept changes in the form changeCreator(sliceName, field, value) | ||
* @param validate A validation function that takes all the data and returns all the errors | ||
*/ | ||
function reduxForm(sliceName) { | ||
function reduxForm(sliceName, validate) { | ||
return function (DecoratedComponent) { | ||
@@ -319,8 +307,9 @@ return (function (_Component) { | ||
handleChange: handleChange, | ||
validate: function () { | ||
return dispatch(_actions.validate(sliceName)); | ||
showAll: function () { | ||
return dispatch(_actions.showAll(sliceName)); | ||
}, | ||
reset: function () { | ||
return dispatch(_actions.reset(sliceName)); | ||
} | ||
}, | ||
errors: validate(slice.data) | ||
}, slice)); | ||
@@ -327,0 +316,0 @@ }; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.ReduxForm=t(require("react")):e.ReduxForm=t(e.React)}(this,function(e){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}t.__esModule=!0;var o=r(6),u=n(o),a=r(7),i=n(a);t.default=i.default,t.createFormReducer=u.default},function(e,t){"use strict";t.__esModule=!0;var r="REDUX_FORM_CHANGE";t.CHANGE=r;var n="REDUX_FORM_VALIDATE";t.VALIDATE=n;var o="REDUX_FORM_RESET";t.RESET=o},function(e,t){"use strict";function r(e){return e.shape({subscribe:e.func.isRequired,dispatch:e.func.isRequired,getState:e.func.isRequired})}t.__esModule=!0,t.default=r,e.exports=t.default},function(e,t){"use strict";function r(e){return e.displayName||e.name||"Component"}t.__esModule=!0,t.default=r,e.exports=t.default},function(t,r){t.exports=e},function(e,t,r){"use strict";function n(e,t,r){return{type:a.CHANGE,form:e,field:t,value:r}}function o(e){return{type:a.VALIDATE,form:e}}function u(e){return{type:a.RESET,form:e}}t.__esModule=!0,t.change=n,t.validate=o,t.reset=u;var a=r(1)},function(e,t,r){"use strict";function n(e,t){var r=arguments.length<=2||void 0===arguments[2]?function(){}:arguments[2],n=arguments.length<=3||void 0===arguments[3]?{}:arguments[3];return function(){var a,i,c=arguments.length<=0||void 0===arguments[0]?{data:n,errors:{},visited:{}}:arguments[0],s=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if(s.form!==e)return c;switch(s.type){case u.CHANGE:var l=o({},c.data,(a={},a[s.field]=s.value,a));return o({},c,{data:l,errors:r(l),visited:o({},c.visited,(i={},i[s.field]=!0,i))});case u.VALIDATE:var f=r(c.data),p=c.visited;return t.forEach(function(e){return p[e]=!0}),o({},c,{errors:f,visited:p});case u.RESET:return{data:n,errors:{},visited:{}};default:return c}}}t.__esModule=!0;var o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e};t.default=n;var u=r(1);e.exports=t.default},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function a(e){return function(t){return function(r){function n(){o(this,a),r.apply(this,arguments)}u(n,r),n.prototype.render=function(){var r=this.props,n=r.slice,o=r.dispatch,u=function(t){return function(r){return o(p.change(e,t,r.target.value))}};return l.default.createElement(t,i({handleChange:u,validate:function(){return o(p.validate(e))},reset:function(){return o(p.reset(e))}},n))},c(n,null,[{key:"displayName",value:"ReduxForm("+d(t)+")",enumerable:!0},{key:"DecoratedComponent",value:t,enumerable:!0},{key:"propTypes",value:{slice:s.PropTypes.object,dispatch:s.PropTypes.func.isRequired},enumerable:!0}]);var a=n;return n=f.connect(function(t){return{slice:t[e]}})(n)||n}(s.Component)}}t.__esModule=!0;var i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},c=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();t.default=a;var s=r(4),l=n(s),f=r(13),p=r(5),d=function(e){return e.displayName||e.name||"Component"};e.exports=t.default},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function o(e){var t=a.default(e),r=l.default(e),n=c.default(e,t),o=p.default(e,r);return{Provider:t,Connector:r,provide:n,connect:o}}t.__esModule=!0,t.default=o;var u=r(12),a=n(u),i=r(11),c=n(i),s=r(10),l=n(s),f=r(9),p=n(f);e.exports=t.default},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(e.__proto__=t)}function a(e,t){var r=e.Component;return function(n){return function(a){return function(r){function s(){o(this,s),r.apply(this,arguments)}return u(s,r),s.prototype.shouldComponentUpdate=function(e){return!p.default(this.props,e)},s.prototype.render=function(){var r=this;return e.createElement(t,{select:function(e){return n(e,r.props)}},function(t){return e.createElement(a,i({},t,r.props))})},c(s,null,[{key:"displayName",value:"Connector("+l.default(a)+")",enumerable:!0},{key:"DecoratedComponent",value:a,enumerable:!0}]),s}(r)}}}t.__esModule=!0;var i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},c=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();t.default=a;var s=r(3),l=n(s),f=r(16),p=n(f);e.exports=t.default},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(e.__proto__=t)}function a(e){var t=e.Component,r=e.PropTypes,n=l.default(r);return function(e){function t(r,n){o(this,t),e.call(this,r,n),this.state=this.selectState(r,n)}return u(t,e),t.prototype.shouldComponentUpdate=function(e,t){return!this.isSliceEqual(this.state.slice,t.slice)||!p.default(this.props,e)},t.prototype.isSliceEqual=function(e,t){var r=e===t;return r?!0:"object"!=typeof e||"object"!=typeof t?r:p.default(e,t)},t.prototype.componentDidMount=function(){this.unsubscribe=this.context.store.subscribe(this.handleChange.bind(this)),this.handleChange()},t.prototype.componentWillReceiveProps=function(e){e.select!==this.props.select&&this.handleChange(e)},t.prototype.componentWillUnmount=function(){this.unsubscribe()},t.prototype.handleChange=function(){var e=void 0===arguments[0]?this.props:arguments[0],t=this.selectState(e,this.context);this.isSliceEqual(this.state.slice,t.slice)||this.setState(t)},t.prototype.selectState=function(e,t){var r=t.store.getState(),n=e.select(r);return h.default(v.default(n),"The return value of `select` prop must be an object. Instead received %s.",n),{slice:n}},t.prototype.render=function(){var e=this.props.children,t=this.state.slice,r=this.context.store.dispatch;return e(i({dispatch:r},t))},c(t,null,[{key:"contextTypes",value:{store:n.isRequired},enumerable:!0},{key:"propTypes",value:{children:r.func.isRequired,select:r.func.isRequired},enumerable:!0},{key:"defaultProps",value:{select:function(e){return e}},enumerable:!0}]),t}(t)}t.__esModule=!0;var i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},c=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();t.default=a;var s=r(2),l=n(s),f=r(15),p=n(f),d=r(14),v=n(d),y=r(17),h=n(y);e.exports=t.default},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(e.__proto__=t)}function a(e,t){var r=e.Component;return function(n){return function(a){return function(r){function c(){o(this,c),r.apply(this,arguments)}return u(c,r),c.prototype.render=function(){var r=this;return e.createElement(t,{store:n},function(){return e.createElement(a,r.props)})},i(c,null,[{key:"displayName",value:"Provider("+s.default(a)+")",enumerable:!0},{key:"DecoratedComponent",value:a,enumerable:!0}]),c}(r)}}}t.__esModule=!0;var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();t.default=a;var c=r(3),s=n(c);e.exports=t.default},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(e.__proto__=t)}function a(e){var t=e.Component,r=e.PropTypes,n=s.default(r);return function(e){function t(r,n){o(this,t),e.call(this,r,n),this.state={store:r.store}}return u(t,e),t.prototype.getChildContext=function(){return{store:this.state.store}},t.prototype.componentWillReceiveProps=function(e){var t=this.state.store,r=e.store;if(t!==r){var n=r.getReducer();t.replaceReducer(n)}},t.prototype.render=function(){var e=this.props.children;return e()},i(t,null,[{key:"childContextTypes",value:{store:n.isRequired},enumerable:!0},{key:"propTypes",value:{children:r.func.isRequired},enumerable:!0}]),t}(t)}t.__esModule=!0;var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();t.default=a;var c=r(2),s=n(c);e.exports=t.default},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}t.__esModule=!0;var o=r(4),u=n(o),a=r(8),i=n(a),c=i.default(u.default),s=c.Provider,l=c.Connector,f=c.provide,p=c.connect;t.Provider=s,t.Connector=l,t.provide=f,t.connect=p},function(e,t){"use strict";function r(e){return e?"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype:!1}t.__esModule=!0,t.default=r,e.exports=t.default},function(e,t){"use strict";function r(e,t){if(e===t)return!0;var r=Object.keys(e),n=Object.keys(t);if(r.length!==n.length)return!1;for(var o=Object.prototype.hasOwnProperty,u=0;u<r.length;u++)if(!o.call(t,r[u])||e[r[u]]!==t[r[u]])return!1;return!0}t.__esModule=!0,t.default=r,e.exports=t.default},function(e,t){"use strict";function r(e,t){if(e===t)return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;var r=Object.keys(e),n=Object.keys(t);if(r.length!==n.length)return!1;for(var o=Object.prototype.hasOwnProperty,u=0;u<r.length;u++){if(!o.call(t,r[u]))return!1;var a=e[r[u]],i=t[r[u]];if(a!==i||"object"==typeof a||"object"==typeof i)return!1}return!0}t.__esModule=!0,t.default=r,e.exports=t.default},function(e,t,r){"use strict";var n=function(e,t,r,n,o,u,a,i){if(!e){var c;if(void 0===t)c=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var s=[r,n,o,u,a,i],l=0;c=new Error("Invariant Violation: "+t.replace(/%s/g,function(){return s[l++]}))}throw c.framesToPop=1,c}};e.exports=n}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.ReduxForm=t(require("react")):e.ReduxForm=t(e.React)}(this,function(e){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}t.__esModule=!0;var o=r(6),u=n(o),a=r(7),i=n(a);t.default=i.default,t.createFormReducer=u.default},function(e,t){"use strict";t.__esModule=!0;var r="REDUX_FORM_CHANGE";t.CHANGE=r;var n="REDUX_FORM_SHOW_ALL";t.SHOW_ALL=n;var o="REDUX_FORM_RESET";t.RESET=o},function(e,t){"use strict";function r(e){return e.shape({subscribe:e.func.isRequired,dispatch:e.func.isRequired,getState:e.func.isRequired})}t.__esModule=!0,t.default=r,e.exports=t.default},function(e,t){"use strict";function r(e){return e.displayName||e.name||"Component"}t.__esModule=!0,t.default=r,e.exports=t.default},function(t,r){t.exports=e},function(e,t,r){"use strict";function n(e,t,r){return{type:a.CHANGE,form:e,field:t,value:r}}function o(e){return{type:a.SHOW_ALL,form:e}}function u(e){return{type:a.RESET,form:e}}t.__esModule=!0,t.change=n,t.showAll=o,t.reset=u;var a=r(1)},function(e,t,r){"use strict";function n(e,t){var r=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],n={data:r,visited:{}};return function(){var r,a,i=arguments.length<=0||void 0===arguments[0]?n:arguments[0],c=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if(c.form!==e)return i;switch(c.type){case u.CHANGE:var s=o({},i.data,(r={},r[c.field]=c.value,r));return o({},i,{data:s,visited:o({},i.visited,(a={},a[c.field]=!0,a))});case u.SHOW_ALL:var l={};return t.forEach(function(e){return l[e]=!0}),o({},i,{visited:l});case u.RESET:return n;default:return i}}}t.__esModule=!0;var o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e};t.default=n;var u=r(1);e.exports=t.default},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function a(e,t){return function(r){return function(n){function a(){o(this,y),n.apply(this,arguments)}u(a,n),a.prototype.render=function(){var n=this.props,o=n.slice,u=n.dispatch,a=function(t){return function(r){return u(p.change(e,t,r.target.value))}};return l.default.createElement(r,i({handleChange:a,showAll:function(){return u(p.showAll(e))},reset:function(){return u(p.reset(e))},errors:t(o.data)},o))},c(a,null,[{key:"displayName",value:"ReduxForm("+d(r)+")",enumerable:!0},{key:"DecoratedComponent",value:r,enumerable:!0},{key:"propTypes",value:{slice:s.PropTypes.object,dispatch:s.PropTypes.func.isRequired},enumerable:!0}]);var y=a;return a=f.connect(function(t){return{slice:t[e]}})(a)||a}(s.Component)}}t.__esModule=!0;var i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},c=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();t.default=a;var s=r(4),l=n(s),f=r(13),p=r(5),d=function(e){return e.displayName||e.name||"Component"};e.exports=t.default},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function o(e){var t=a.default(e),r=l.default(e),n=c.default(e,t),o=p.default(e,r);return{Provider:t,Connector:r,provide:n,connect:o}}t.__esModule=!0,t.default=o;var u=r(12),a=n(u),i=r(11),c=n(i),s=r(10),l=n(s),f=r(9),p=n(f);e.exports=t.default},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(e.__proto__=t)}function a(e,t){var r=e.Component;return function(n){return function(a){return function(r){function s(){o(this,s),r.apply(this,arguments)}return u(s,r),s.prototype.shouldComponentUpdate=function(e){return!p.default(this.props,e)},s.prototype.render=function(){var r=this;return e.createElement(t,{select:function(e){return n(e,r.props)}},function(t){return e.createElement(a,i({},t,r.props))})},c(s,null,[{key:"displayName",value:"Connector("+l.default(a)+")",enumerable:!0},{key:"DecoratedComponent",value:a,enumerable:!0}]),s}(r)}}}t.__esModule=!0;var i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},c=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();t.default=a;var s=r(3),l=n(s),f=r(16),p=n(f);e.exports=t.default},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(e.__proto__=t)}function a(e){var t=e.Component,r=e.PropTypes,n=l.default(r);return function(e){function t(r,n){o(this,t),e.call(this,r,n),this.state=this.selectState(r,n)}return u(t,e),t.prototype.shouldComponentUpdate=function(e,t){return!this.isSliceEqual(this.state.slice,t.slice)||!p.default(this.props,e)},t.prototype.isSliceEqual=function(e,t){var r=e===t;return r?!0:"object"!=typeof e||"object"!=typeof t?r:p.default(e,t)},t.prototype.componentDidMount=function(){this.unsubscribe=this.context.store.subscribe(this.handleChange.bind(this)),this.handleChange()},t.prototype.componentWillReceiveProps=function(e){e.select!==this.props.select&&this.handleChange(e)},t.prototype.componentWillUnmount=function(){this.unsubscribe()},t.prototype.handleChange=function(){var e=void 0===arguments[0]?this.props:arguments[0],t=this.selectState(e,this.context);this.isSliceEqual(this.state.slice,t.slice)||this.setState(t)},t.prototype.selectState=function(e,t){var r=t.store.getState(),n=e.select(r);return h.default(y.default(n),"The return value of `select` prop must be an object. Instead received %s.",n),{slice:n}},t.prototype.render=function(){var e=this.props.children,t=this.state.slice,r=this.context.store.dispatch;return e(i({dispatch:r},t))},c(t,null,[{key:"contextTypes",value:{store:n.isRequired},enumerable:!0},{key:"propTypes",value:{children:r.func.isRequired,select:r.func.isRequired},enumerable:!0},{key:"defaultProps",value:{select:function(e){return e}},enumerable:!0}]),t}(t)}t.__esModule=!0;var i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},c=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();t.default=a;var s=r(2),l=n(s),f=r(15),p=n(f),d=r(14),y=n(d),v=r(17),h=n(v);e.exports=t.default},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(e.__proto__=t)}function a(e,t){var r=e.Component;return function(n){return function(a){return function(r){function c(){o(this,c),r.apply(this,arguments)}return u(c,r),c.prototype.render=function(){var r=this;return e.createElement(t,{store:n},function(){return e.createElement(a,r.props)})},i(c,null,[{key:"displayName",value:"Provider("+s.default(a)+")",enumerable:!0},{key:"DecoratedComponent",value:a,enumerable:!0}]),c}(r)}}}t.__esModule=!0;var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();t.default=a;var c=r(3),s=n(c);e.exports=t.default},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(e.__proto__=t)}function a(e){var t=e.Component,r=e.PropTypes,n=s.default(r);return function(e){function t(r,n){o(this,t),e.call(this,r,n),this.state={store:r.store}}return u(t,e),t.prototype.getChildContext=function(){return{store:this.state.store}},t.prototype.componentWillReceiveProps=function(e){var t=this.state.store,r=e.store;if(t!==r){var n=r.getReducer();t.replaceReducer(n)}},t.prototype.render=function(){var e=this.props.children;return e()},i(t,null,[{key:"childContextTypes",value:{store:n.isRequired},enumerable:!0},{key:"propTypes",value:{children:r.func.isRequired},enumerable:!0}]),t}(t)}t.__esModule=!0;var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();t.default=a;var c=r(2),s=n(c);e.exports=t.default},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}t.__esModule=!0;var o=r(4),u=n(o),a=r(8),i=n(a),c=i.default(u.default),s=c.Provider,l=c.Connector,f=c.provide,p=c.connect;t.Provider=s,t.Connector=l,t.provide=f,t.connect=p},function(e,t){"use strict";function r(e){return e?"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype:!1}t.__esModule=!0,t.default=r,e.exports=t.default},function(e,t){"use strict";function r(e,t){if(e===t)return!0;var r=Object.keys(e),n=Object.keys(t);if(r.length!==n.length)return!1;for(var o=Object.prototype.hasOwnProperty,u=0;u<r.length;u++)if(!o.call(t,r[u])||e[r[u]]!==t[r[u]])return!1;return!0}t.__esModule=!0,t.default=r,e.exports=t.default},function(e,t){"use strict";function r(e,t){if(e===t)return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;var r=Object.keys(e),n=Object.keys(t);if(r.length!==n.length)return!1;for(var o=Object.prototype.hasOwnProperty,u=0;u<r.length;u++){if(!o.call(t,r[u]))return!1;var a=e[r[u]],i=t[r[u]];if(a!==i||"object"==typeof a||"object"==typeof i)return!1}return!0}t.__esModule=!0,t.default=r,e.exports=t.default},function(e,t,r){"use strict";var n=function(e,t,r,n,o,u,a,i){if(!e){var c;if(void 0===t)c=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var s=[r,n,o,u,a,i],l=0;c=new Error("Invariant Violation: "+t.replace(/%s/g,function(){return s[l++]}))}throw c.framesToPop=1,c}};e.exports=n}])}); |
@@ -5,3 +5,3 @@ 'use strict'; | ||
exports.change = change; | ||
exports.validate = validate; | ||
exports.showAll = showAll; | ||
exports.reset = reset; | ||
@@ -20,5 +20,5 @@ | ||
function validate(form) { | ||
function showAll(form) { | ||
return { | ||
type: _actionTypes.VALIDATE, | ||
type: _actionTypes.SHOW_ALL, | ||
form: form | ||
@@ -25,0 +25,0 @@ }; |
@@ -6,5 +6,5 @@ 'use strict'; | ||
exports.CHANGE = CHANGE; | ||
var VALIDATE = 'REDUX_FORM_VALIDATE'; | ||
exports.VALIDATE = VALIDATE; | ||
var SHOW_ALL = 'REDUX_FORM_SHOW_ALL'; | ||
exports.SHOW_ALL = SHOW_ALL; | ||
var RESET = 'REDUX_FORM_RESET'; | ||
exports.RESET = RESET; |
@@ -18,6 +18,2 @@ 'use strict'; | ||
* }, | ||
* errors: { | ||
* field1: 'error for field1', | ||
* field2: 'error for field2' | ||
* }, | ||
* visited: { | ||
@@ -32,4 +28,3 @@ * field1: true, | ||
* @param name the name of the "state slice" where the data is stored | ||
* @param fields an array of field names, used when validating all values | ||
* @param validate a validation function that takes all the data and returns all the errors | ||
* @param fields an array of field names, used when showing all values | ||
* @param initialData initial data to populate the state with | ||
@@ -40,7 +35,7 @@ * @returns {Function} a form reducer | ||
function createFormReducer(name, fields) { | ||
var validate = arguments.length <= 2 || arguments[2] === undefined ? function () {} : arguments[2]; | ||
var initialData = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; | ||
var initialData = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
var initialState = { data: initialData, visited: {} }; | ||
return function () { | ||
var state = arguments.length <= 0 || arguments[0] === undefined ? { data: initialData, errors: {}, visited: {} } : arguments[0]; | ||
var state = arguments.length <= 0 || arguments[0] === undefined ? initialState : arguments[0]; | ||
@@ -59,8 +54,6 @@ var _extends2, _extends3; | ||
data: data, | ||
errors: validate(data), | ||
visited: _extends({}, state.visited, (_extends3 = {}, _extends3[action.field] = true, _extends3)) | ||
}); | ||
case _actionTypes.VALIDATE: | ||
var errors = validate(state.data); | ||
var visited = state.visited; | ||
case _actionTypes.SHOW_ALL: | ||
var visited = {}; | ||
fields.forEach(function (key) { | ||
@@ -70,11 +63,6 @@ return visited[key] = true; | ||
return _extends({}, state, { | ||
errors: errors, | ||
visited: visited | ||
}); | ||
case _actionTypes.RESET: | ||
return { | ||
data: initialData, | ||
errors: {}, | ||
visited: {} | ||
}; | ||
return initialState; | ||
default: | ||
@@ -81,0 +69,0 @@ return state; |
@@ -31,6 +31,6 @@ 'use strict'; | ||
* @param sliceName The key in the state corresponding to the data in this form | ||
* @param changeCreator An action creator to accept changes in the form changeCreator(sliceName, field, value) | ||
* @param validate A validation function that takes all the data and returns all the errors | ||
*/ | ||
function reduxForm(sliceName) { | ||
function reduxForm(sliceName, validate) { | ||
return function (DecoratedComponent) { | ||
@@ -58,8 +58,9 @@ return (function (_Component) { | ||
handleChange: handleChange, | ||
validate: function () { | ||
return dispatch(_actions.validate(sliceName)); | ||
showAll: function () { | ||
return dispatch(_actions.showAll(sliceName)); | ||
}, | ||
reset: function () { | ||
return dispatch(_actions.reset(sliceName)); | ||
} | ||
}, | ||
errors: validate(slice.data) | ||
}, slice)); | ||
@@ -66,0 +67,0 @@ }; |
{ | ||
"name": "redux-form", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "An ES7 decorator for forms using Redux and React", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -19,3 +19,3 @@ #redux-form | ||
When used in conjunction with [React Hot Loader](https://github.com/gaearon/react-hot-loader), you can modify your components, rebuild your app and immediately see your changes ***without losing your form data***. This may seem trivial, but the minutes of refilling out forms in a develomnet environment really add up. | ||
When used in conjunction with [React Hot Loader](https://github.com/gaearon/react-hot-loader), you can modify your components, rebuild your app and immediately see your changes ***without losing your form data***. This may seem trivial, but the minutes of refilling out forms in a development environment really add up. | ||
@@ -35,3 +35,3 @@ #### Stateless Components | ||
// ... your other reducers here ... | ||
createFormReducer('contacts', ['name', 'address', 'phone'], contactValidation) | ||
createFormReducer('contacts', ['name', 'address', 'phone']) | ||
} | ||
@@ -47,4 +47,5 @@ const reducer = combineReducers(reducers); | ||
import reduxForm from 'redux-form'; | ||
import contactValidation from './contactValidation'; | ||
@reduxForm('contacts') | ||
@reduxForm('contacts', contactValidation) | ||
export default class ContactForm extends Component { | ||
@@ -55,3 +56,3 @@ static propTypes = { | ||
handleChange: PropTypes.func.isRequired, | ||
validate: PropTypes.func.isRequired, | ||
showAll: PropTypes.func.isRequired, | ||
reset: PropTypes.func.isRequired | ||
@@ -63,3 +64,4 @@ } | ||
data: {name, address, phone}, | ||
errors: {name: nameError, address: addressError, phone: phoneError} | ||
errors: {name: nameError, address: addressError, phone: phoneError}, | ||
handleChange | ||
} = this.props; | ||
@@ -134,2 +136,30 @@ return ( | ||
### props | ||
The props passed into your decorated component will be: | ||
##### -`handleChange(field:string) : Function` | ||
> returns a `handleChange` function for the field passed. | ||
##### -`showAll() : Function` | ||
> marks all fields as "visited" to show errors. should be called on form submission. | ||
##### -`reset() : Function` | ||
> clears all the values in the form | ||
##### -`data:Object` | ||
> the form data, in the form `{ field1: <string>, field2: <string> }` | ||
##### -`errors:Object` | ||
> all the errors, in the form `{ field1: <string>, field2: <string> }` | ||
##### -`visited:Object` | ||
> the visited flags for each field, in the form `{ field1: <boolean>, field2: <boolean> }` | ||
## Running Example | ||
@@ -136,0 +166,0 @@ |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
164
0
90628
904