@restart/context
Advanced tools
Comparing version 2.1.2 to 2.1.4
import React from 'react'; | ||
export default function forwardRef(renderFn, _temp) { | ||
let _ref = _temp === void 0 ? {} : _temp, | ||
var _ref = _temp === void 0 ? {} : _temp, | ||
propTypes = _ref.propTypes, | ||
@@ -11,9 +11,13 @@ defaultProps = _ref.defaultProps, | ||
const render = (props, ref) => renderFn(props, ref); | ||
var render = function render(props, ref) { | ||
return renderFn(props, ref); | ||
}; | ||
return Object.assign(React.forwardRef || !allowFallback ? React.forwardRef(render) : props => render(props, null), { | ||
displayName, | ||
propTypes, | ||
defaultProps | ||
return Object.assign(React.forwardRef || !allowFallback ? React.forwardRef(render) : function (props) { | ||
return render(props, null); | ||
}, { | ||
displayName: displayName, | ||
propTypes: propTypes, | ||
defaultProps: defaultProps | ||
}); | ||
} |
import mapContextToProps from './mapContextToProps'; | ||
export default ((Context, prop, Component) => mapContextToProps(Context, context => ({ | ||
[prop]: context | ||
}), Component)); | ||
export default (function (Context, prop, Component) { | ||
return mapContextToProps(Context, function (context) { | ||
var _ref; | ||
return _ref = {}, _ref[prop] = context, _ref; | ||
}, Component); | ||
}); |
@@ -6,11 +6,13 @@ function _extends() { _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; }; return _extends.apply(this, arguments); } | ||
const getDisplayName = Component => { | ||
const name = typeof Component === 'string' ? Component : Component.name || Component.displayName; | ||
return name ? `ContextTransform(${name})` : 'ContextTransform'; | ||
var getDisplayName = function getDisplayName(Component) { | ||
var name = typeof Component === 'string' ? Component : Component.name || Component.displayName; | ||
return name ? "ContextTransform(" + name + ")" : 'ContextTransform'; | ||
}; | ||
const ensureConsumer = c => c.Consumer || c; | ||
var ensureConsumer = function ensureConsumer(c) { | ||
return c.Consumer || c; | ||
}; | ||
function $mapContextToProps(_ref, Component) { | ||
let maybeArrayOfConsumers = _ref.consumers, | ||
var maybeArrayOfConsumers = _ref.consumers, | ||
mapToProps = _ref.mapToProps, | ||
@@ -20,3 +22,3 @@ displayName = _ref.displayName, | ||
forwardRefAs = _ref$forwardRefAs === void 0 ? 'ref' : _ref$forwardRefAs; | ||
let consumers = maybeArrayOfConsumers; | ||
var consumers = maybeArrayOfConsumers; | ||
@@ -27,24 +29,30 @@ if (!Array.isArray(maybeArrayOfConsumers)) { | ||
const SingleConsumer = ensureConsumer(consumers[0]); | ||
var SingleConsumer = ensureConsumer(consumers[0]); | ||
function singleRender(props, ref) { | ||
const propsWithRef = _extends({ | ||
[forwardRefAs]: ref | ||
}, props); | ||
var _extends2; | ||
return React.createElement(SingleConsumer, null, value => React.createElement(Component, _extends({}, propsWithRef, mapToProps(value, props)))); | ||
var propsWithRef = _extends((_extends2 = {}, _extends2[forwardRefAs] = ref, _extends2), props); | ||
return React.createElement(SingleConsumer, null, function (value) { | ||
return React.createElement(Component, _extends({}, propsWithRef, mapToProps(value, props))); | ||
}); | ||
} | ||
function multiRender(props, ref) { | ||
const propsWithRef = _extends({ | ||
[forwardRefAs]: ref | ||
}, props); | ||
var _extends3; | ||
return consumers.reduceRight((inner, Context) => function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
var propsWithRef = _extends((_extends3 = {}, _extends3[forwardRefAs] = ref, _extends3), props); | ||
const Consumer = ensureConsumer(Context); | ||
return React.createElement(Consumer, null, value => inner(...args, value)); | ||
return consumers.reduceRight(function (inner, Context) { | ||
return function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
var Consumer = ensureConsumer(Context); | ||
return React.createElement(Consumer, null, function (value) { | ||
return inner.apply(void 0, args.concat([value])); | ||
}); | ||
}; | ||
}, function () { | ||
@@ -55,7 +63,7 @@ for (var _len2 = arguments.length, contexts = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
return React.createElement(Component, _extends({}, propsWithRef, mapToProps(...contexts, props))); | ||
return React.createElement(Component, _extends({}, propsWithRef, mapToProps.apply(void 0, contexts.concat([props])))); | ||
})(); | ||
} | ||
const contextTransform = consumers.length === 1 ? singleRender : multiRender; | ||
var contextTransform = consumers.length === 1 ? singleRender : multiRender; | ||
return forwardRef(contextTransform, { | ||
@@ -70,4 +78,4 @@ displayName: displayName || getDisplayName(Component) | ||
consumers: maybeOpts, | ||
mapToProps | ||
mapToProps: mapToProps | ||
}, Component); | ||
} |
import React from 'react'; | ||
import forwardRef from './forwardRef'; | ||
export default function transformContext(Context) { | ||
return forwardRef(props => React.createElement(Context.Consumer, null, context => React.createElement(Context.Provider, { | ||
value: props.mapToValue(context) | ||
}, props.children)), { | ||
return forwardRef(function (props) { | ||
return React.createElement(Context.Consumer, null, function (context) { | ||
return React.createElement(Context.Provider, { | ||
value: props.mapToValue(context) | ||
}, props.children); | ||
}); | ||
}, { | ||
displayName: 'ContextTransformer' | ||
}); | ||
} |
@@ -11,3 +11,3 @@ "use strict"; | ||
function forwardRef(renderFn, _temp) { | ||
let _ref = _temp === void 0 ? {} : _temp, | ||
var _ref = _temp === void 0 ? {} : _temp, | ||
propTypes = _ref.propTypes, | ||
@@ -20,9 +20,13 @@ defaultProps = _ref.defaultProps, | ||
const render = (props, ref) => renderFn(props, ref); | ||
var render = function render(props, ref) { | ||
return renderFn(props, ref); | ||
}; | ||
return Object.assign(_react.default.forwardRef || !allowFallback ? _react.default.forwardRef(render) : props => render(props, null), { | ||
displayName, | ||
propTypes, | ||
defaultProps | ||
return Object.assign(_react.default.forwardRef || !allowFallback ? _react.default.forwardRef(render) : function (props) { | ||
return render(props, null); | ||
}, { | ||
displayName: displayName, | ||
propTypes: propTypes, | ||
defaultProps: defaultProps | ||
}); | ||
} |
@@ -10,6 +10,10 @@ "use strict"; | ||
var _default = (Context, prop, Component) => (0, _mapContextToProps.default)(Context, context => ({ | ||
[prop]: context | ||
}), Component); | ||
var _default = function _default(Context, prop, Component) { | ||
return (0, _mapContextToProps.default)(Context, function (context) { | ||
var _ref; | ||
return _ref = {}, _ref[prop] = context, _ref; | ||
}, Component); | ||
}; | ||
exports.default = _default; |
@@ -14,11 +14,13 @@ "use strict"; | ||
const getDisplayName = Component => { | ||
const name = typeof Component === 'string' ? Component : Component.name || Component.displayName; | ||
return name ? `ContextTransform(${name})` : 'ContextTransform'; | ||
var getDisplayName = function getDisplayName(Component) { | ||
var name = typeof Component === 'string' ? Component : Component.name || Component.displayName; | ||
return name ? "ContextTransform(" + name + ")" : 'ContextTransform'; | ||
}; | ||
const ensureConsumer = c => c.Consumer || c; | ||
var ensureConsumer = function ensureConsumer(c) { | ||
return c.Consumer || c; | ||
}; | ||
function $mapContextToProps(_ref, Component) { | ||
let maybeArrayOfConsumers = _ref.consumers, | ||
var maybeArrayOfConsumers = _ref.consumers, | ||
mapToProps = _ref.mapToProps, | ||
@@ -28,3 +30,3 @@ displayName = _ref.displayName, | ||
forwardRefAs = _ref$forwardRefAs === void 0 ? 'ref' : _ref$forwardRefAs; | ||
let consumers = maybeArrayOfConsumers; | ||
var consumers = maybeArrayOfConsumers; | ||
@@ -35,24 +37,30 @@ if (!Array.isArray(maybeArrayOfConsumers)) { | ||
const SingleConsumer = ensureConsumer(consumers[0]); | ||
var SingleConsumer = ensureConsumer(consumers[0]); | ||
function singleRender(props, ref) { | ||
const propsWithRef = _extends({ | ||
[forwardRefAs]: ref | ||
}, props); | ||
var _extends2; | ||
return _react.default.createElement(SingleConsumer, null, value => _react.default.createElement(Component, _extends({}, propsWithRef, mapToProps(value, props)))); | ||
var propsWithRef = _extends((_extends2 = {}, _extends2[forwardRefAs] = ref, _extends2), props); | ||
return _react.default.createElement(SingleConsumer, null, function (value) { | ||
return _react.default.createElement(Component, _extends({}, propsWithRef, mapToProps(value, props))); | ||
}); | ||
} | ||
function multiRender(props, ref) { | ||
const propsWithRef = _extends({ | ||
[forwardRefAs]: ref | ||
}, props); | ||
var _extends3; | ||
return consumers.reduceRight((inner, Context) => function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
var propsWithRef = _extends((_extends3 = {}, _extends3[forwardRefAs] = ref, _extends3), props); | ||
const Consumer = ensureConsumer(Context); | ||
return _react.default.createElement(Consumer, null, value => inner(...args, value)); | ||
return consumers.reduceRight(function (inner, Context) { | ||
return function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
var Consumer = ensureConsumer(Context); | ||
return _react.default.createElement(Consumer, null, function (value) { | ||
return inner.apply(void 0, args.concat([value])); | ||
}); | ||
}; | ||
}, function () { | ||
@@ -63,7 +71,7 @@ for (var _len2 = arguments.length, contexts = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
return _react.default.createElement(Component, _extends({}, propsWithRef, mapToProps(...contexts, props))); | ||
return _react.default.createElement(Component, _extends({}, propsWithRef, mapToProps.apply(void 0, contexts.concat([props])))); | ||
})(); | ||
} | ||
const contextTransform = consumers.length === 1 ? singleRender : multiRender; | ||
var contextTransform = consumers.length === 1 ? singleRender : multiRender; | ||
return (0, _forwardRef.default)(contextTransform, { | ||
@@ -78,4 +86,4 @@ displayName: displayName || getDisplayName(Component) | ||
consumers: maybeOpts, | ||
mapToProps | ||
mapToProps: mapToProps | ||
}, Component); | ||
} |
{ | ||
"name": "@restart/context", | ||
"version": "2.1.2", | ||
"version": "2.1.4", | ||
"main": "index.js", | ||
@@ -16,6 +16,6 @@ "module": "es/index.js", | ||
}, | ||
"prettier": { | ||
"printWidth": 79, | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "lint-staged" | ||
} | ||
}, | ||
@@ -32,2 +32,7 @@ "lint-staged": { | ||
}, | ||
"prettier": { | ||
"printWidth": 79, | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
}, | ||
"jest": { | ||
@@ -34,0 +39,0 @@ "roots": [ |
@@ -13,7 +13,11 @@ "use strict"; | ||
function transformContext(Context) { | ||
return (0, _forwardRef.default)(props => _react.default.createElement(Context.Consumer, null, context => _react.default.createElement(Context.Provider, { | ||
value: props.mapToValue(context) | ||
}, props.children)), { | ||
return (0, _forwardRef.default)(function (props) { | ||
return _react.default.createElement(Context.Consumer, null, function (context) { | ||
return _react.default.createElement(Context.Provider, { | ||
value: props.mapToValue(context) | ||
}, props.children); | ||
}); | ||
}, { | ||
displayName: 'ContextTransformer' | ||
}); | ||
} |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
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
22826
19
562
0
42