uncontrollable
Advanced tools
Comparing version 4.0.1 to 4.0.2
{ | ||
"name": "uncontrollable", | ||
"version": "4.0.1", | ||
"version": "4.0.2", | ||
"description": "Wrap a controlled react component, to allow specific prop/handler pairs to be uncontrolled", | ||
@@ -5,0 +5,0 @@ "author": { |
36
utils.js
@@ -5,3 +5,2 @@ 'use strict'; | ||
exports.version = undefined; | ||
exports.customPropType = customPropType; | ||
exports.uncontrolledPropTypes = uncontrolledPropTypes; | ||
@@ -15,4 +14,4 @@ exports.getType = getType; | ||
exports.each = each; | ||
exports.has = has; | ||
exports.isReactComponent = isReactComponent; | ||
exports.has = has; | ||
@@ -29,6 +28,17 @@ var _react = require('react'); | ||
function customPropType(handler, propType, name) { | ||
function defaultPropType(controlledPropName, propType) { | ||
return function (props, name) { | ||
for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { | ||
args[_key - 2] = arguments[_key]; | ||
} | ||
return function (props, propName, wrappedName) { | ||
// never consider a defaultProp "required", bit a hack. | ||
if (props[name] != null) { | ||
return propType.apply(undefined, [props, name].concat(args)); | ||
} | ||
}; | ||
} | ||
function readOnlyPropType(handler, name) { | ||
return function (props, propName) { | ||
if (props[propName] !== undefined) { | ||
@@ -38,8 +48,2 @@ if (!props[handler]) { | ||
} | ||
for (var _len = arguments.length, args = Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) { | ||
args[_key - 3] = arguments[_key]; | ||
} | ||
return propType && propType.apply(undefined, [props, propName, name].concat(args)); | ||
} | ||
@@ -58,5 +62,5 @@ }; | ||
obj[prop] = customPropType(handler, type, displayName); | ||
obj[prop] = readOnlyPropType(handler, displayName); | ||
if (type !== undefined) obj[defaultKey(prop)] = type; | ||
if (type !== undefined) obj[defaultKey(prop)] = defaultPropType(prop, type); | ||
}, propTypes); | ||
@@ -120,2 +124,6 @@ } | ||
function has(o, k) { | ||
return o ? Object.prototype.hasOwnProperty.call(o, k) : false; | ||
} | ||
/** | ||
@@ -131,6 +139,2 @@ * Copyright (c) 2013-present, Facebook, Inc. | ||
return !!(component && component.prototype && component.prototype.isReactComponent); | ||
} | ||
function has(o, k) { | ||
return o ? Object.prototype.hasOwnProperty.call(o, k) : false; | ||
} |
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
20038
258