formik-observer
Version:
[](https://www.npmjs.com/package/formik-observer) [ • 5.52 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react'), require('lodash.debounce'), require('lodash.isequal'), require('prop-types')) :
typeof define === 'function' && define.amd ? define('formik-observer', ['react', 'lodash.debounce', 'lodash.isequal', 'prop-types'], factory) :
(global['formik-observer'] = factory(global.react,global.debounce,global.isEqual,global.PropTypes));
}(this, (function (react,debounce,isEqual,PropTypes) { 'use strict';
var react__default = 'default' in react ? react['default'] : react;
debounce = debounce && debounce.hasOwnProperty('default') ? debounce['default'] : debounce;
isEqual = isEqual && isEqual.hasOwnProperty('default') ? isEqual['default'] : isEqual;
PropTypes = PropTypes && PropTypes.hasOwnProperty('default') ? PropTypes['default'] : PropTypes;
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
var createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
var inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
};
var possibleConstructorReturn = function (self, call) {
if (!self) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return call && (typeof call === "object" || typeof call === "function") ? call : self;
};
var _class = function (_Component) {
inherits(_class, _Component);
function _class() {
var _ref;
var _temp, _this, _ret;
classCallCheck(this, _class);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = _class.__proto__ || Object.getPrototypeOf(_class)).call.apply(_ref, [this].concat(args))), _this), _this.onChange = debounce(function (next) {
return _this.props.onChange(next);
}, _this.props.debounce), _temp), possibleConstructorReturn(_this, _ret);
}
createClass(_class, [{
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps, nextContext) {
if (!isEqual(nextContext.formik, this.context.formik)) {
this.onChange(nextContext.formik);
}
}
}, {
key: 'render',
value: function render() {
return null;
}
}]);
return _class;
}(react.Component);
_class.defaultProps = {
debounce: 16,
onChange: function onChange() {
return null;
}
};
_class.contextTypes = {
formik: PropTypes.object
};
return _class;
})));
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VzIjpbImluZGV4LmpzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBSZWFjdCwgeyBDb21wb25lbnQgfSBmcm9tICdyZWFjdCc7XG5pbXBvcnQgZGVib3VuY2UgZnJvbSAnbG9kYXNoLmRlYm91bmNlJztcbmltcG9ydCBpc0VxdWFsIGZyb20gJ2xvZGFzaC5pc2VxdWFsJztcbmltcG9ydCBQcm9wVHlwZXMgZnJvbSAncHJvcC10eXBlcyc7XG5cbmV4cG9ydCBkZWZhdWx0IGNsYXNzIGV4dGVuZHMgQ29tcG9uZW50IHtcbiAgc3RhdGljIGRlZmF1bHRQcm9wcyA9IHtcbiAgICBkZWJvdW5jZTogMTYsXG4gICAgb25DaGFuZ2U6ICgpID0+IG51bGxcbiAgfTtcblxuICBzdGF0aWMgY29udGV4dFR5cGVzID0ge1xuICAgIGZvcm1pazogUHJvcFR5cGVzLm9iamVjdFxuICB9O1xuXG4gIG9uQ2hhbmdlID0gZGVib3VuY2UobmV4dCA9PiB0aGlzLnByb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