Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

substyle

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

substyle - npm Package Compare versions

Comparing version 6.2.1 to 6.3.0

15

lib/coerceSelection.js

@@ -7,10 +7,2 @@ 'use strict';

var _isString2 = require('lodash/isString');
var _isString3 = _interopRequireDefault(_isString2);
var _isPlainObject2 = require('lodash/isPlainObject');
var _isPlainObject3 = _interopRequireDefault(_isPlainObject2);
var _keys2 = require('lodash/keys');

@@ -25,7 +17,8 @@

return [];
} else if ((0, _isString3.default)(select)) {
} else if (typeof select === 'string') {
return [select];
} else if ((0, _isPlainObject3.default)(select)) {
} else if (!Array.isArray(select)) {
var objSelect = select; // workaround for https://github.com/facebook/flow/issues/5781
return (0, _keys3.default)(select).reduce(function (acc, key) {
return acc.concat(select[key] ? [key] : []);
return acc.concat(objSelect[key] ? [key] : []);
}, []);

@@ -32,0 +25,0 @@ }

@@ -15,6 +15,2 @@ 'use strict';

var _isArray2 = require('lodash/isArray');
var _isArray3 = _interopRequireDefault(_isArray2);
var _isPlainObject2 = require('lodash/isPlainObject');

@@ -24,6 +20,2 @@

var _isFunction2 = require('lodash/isFunction');
var _isFunction3 = _interopRequireDefault(_isFunction2);
var _compact2 = require('lodash/compact');

@@ -106,10 +98,8 @@

var styleIsFunction = (0, _isFunction3.default)(style);
var baseClassName = className || guessBaseClassName(classNames);
var substyle = styleIsFunction ? style : (0, _memoize2.default)(function (select, defaultStyle) {
var substyle = typeof style === 'function' ? style : (0, _memoize2.default)(function (select, defaultStyle) {
var selectedKeys = (0, _coerceSelection2.default)(select);
(0, _invariant2.default)((0, _isArray3.default)(selectedKeys), 'First parameter must be a string, an array of strings, ' + 'a plain object with boolean values, or a falsy value.');
(0, _invariant2.default)(Array.isArray(selectedKeys), 'First parameter must be a string, an array of strings, ' + 'a plain object with boolean values, or a falsy value.');

@@ -140,3 +130,5 @@ (0, _invariant2.default)(!defaultStyle || (0, _isPlainObject3.default)(defaultStyle), 'Optional second parameter must be a plain object.');

var styleProps = _extends({}, styleIsFunction ? style : { style: style });
// $FlowFixMe Flow does not believe that also a function can be spread
var styleProps = _extends({}, typeof style === 'function' ? style : { style: style });
var classNameSplit = [].concat(_toConsumableArray(styleProps.className ? styleProps.className.split(' ') : []), _toConsumableArray(baseClassName ? baseClassName.split(' ') : []));

@@ -147,5 +139,5 @@ var mappedClassNames = classNames ? (0, _compact3.default)(classNameSplit.map(function (singleClassName) {

var propsForSpread = propsDecorator(_extends({}, styleProps, mappedClassNames.length > 0 && {
var propsForSpread = propsDecorator(_extends({}, styleProps, mappedClassNames.length > 0 ? {
className: mappedClassNames.join(' ')
}));
} : {}));

@@ -152,0 +144,0 @@ // assign `style` and/or `className` props to the return function object

@@ -7,6 +7,2 @@ 'use strict';

var _isFunction2 = require('lodash/isFunction');
var _isFunction3 = _interopRequireDefault(_isFunction2);
var _identity2 = require('lodash/identity');

@@ -16,6 +12,2 @@

var _omit2 = require('lodash/omit');
var _omit3 = _interopRequireDefault(_omit2);
var _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; };

@@ -31,2 +23,6 @@

var _warning = require('warning');
var _warning2 = _interopRequireDefault(_warning);
var _createSubstyle = require('./createSubstyle');

@@ -48,4 +44,6 @@

var isStatelessFunction = function isStatelessFunction(Component) {
return !Component.prototype.render;
var isStatelessFunction = function isStatelessFunction(Component
// $FlowFixMe
) {
return Component.prototype && !Component.prototype.render;
};

@@ -66,10 +64,22 @@

_this.setWrappedInstance = function (ref) {
_this.wrappedInstance = ref;
var innerRef = _this.props.innerRef;
if (typeof innerRef === 'function') {
innerRef(ref);
} else if (innerRef && typeof innerRef !== 'string') {
innerRef.current = ref;
}
};
var style = props.style,
className = props.className,
classNames = props.classNames,
rest = _objectWithoutProperties(props, ['style', 'className', 'classNames']);
_ = props.innerRef,
rest = _objectWithoutProperties(props, ['style', 'className', 'classNames', 'innerRef']);
_this.substyle = (0, _createSubstyle2.default)({ style: style, className: className, classNames: classNames }, _this.context[_types.PROPS_DECORATOR_CONTEXT_NAME]);
_this.setWrappedInstance = _this.setWrappedInstance.bind(_this);
if ((0, _isFunction3.default)(defaultStyle)) {
if (typeof defaultStyle === 'function') {
_this.defaultStyle = defaultStyle(rest);

@@ -81,4 +91,4 @@ }

_createClass(WithDefaultStyle, [{
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(_ref) {
key: 'shouldComponentUpdate',
value: function shouldComponentUpdate(_ref) {
var style = _ref.style,

@@ -93,3 +103,4 @@ className = _ref.className,

prevClassNames = _props.classNames,
prevRest = _objectWithoutProperties(_props, ['style', 'className', 'classNames']);
_ = _props.innerRef,
prevRest = _objectWithoutProperties(_props, ['style', 'className', 'classNames', 'innerRef']);

@@ -100,3 +111,3 @@ if (style !== prevStyle || className !== prevClassName || classNames !== prevClassNames) {

if ((0, _isFunction3.default)(defaultStyle)) {
if (typeof defaultStyle === 'function') {
if (shouldUpdate(rest, prevRest)) {

@@ -106,2 +117,4 @@ this.defaultStyle = defaultStyle(rest);

}
return true;
}

@@ -111,8 +124,15 @@ }, {

value: function render() {
var rest = (0, _omit3.default)(this.props, ['style', 'className', 'classNames']);
var _props2 = this.props,
innerRef = _props2.innerRef,
_0 = _props2.style,
_1 = _props2.className,
_2 = _props2.classNames,
rest = _objectWithoutProperties(_props2, ['innerRef', 'style', 'className', 'classNames']);
var EnhancedWrappedComponent = this.getWrappedComponent();
var modifiers = getModifiers && getModifiers(rest);
var modifiers = getModifiers ? getModifiers(rest) : [];
return (0, _react.createElement)(EnhancedWrappedComponent, _extends({
style: this.substyle(modifiers, this.defaultStyle || defaultStyle),
ref: isStatelessFunction(EnhancedWrappedComponent) ? undefined : this.setWrappedInstance
ref: isStatelessFunction(EnhancedWrappedComponent) ? undefined : // $FlowFixMe
this.setWrappedInstance
}, rest));

@@ -142,9 +162,5 @@ }

value: function getWrappedInstance() {
(0, _warning2.default)(true, '`getWrappedInstance()` is deprecated and will be removed with the next major release. ' + 'Instead, use the `innerRef` prop to get a ref to the wrapped instance.');
return this.wrappedInstance;
}
}, {
key: 'setWrappedInstance',
value: function setWrappedInstance(ref) {
this.wrappedInstance = ref;
}
}]);

@@ -151,0 +167,0 @@

@@ -11,4 +11,2 @@ 'use strict';

var _types = require('./types');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -18,2 +16,3 @@

var memoize = function memoize(substyle) {

@@ -31,3 +30,3 @@ return function (select, defaultStyle) {

var selectHash = (0, _coerceSelection2.default)(select).join(' ');
return selectHash in mapEntry ? mapEntry[selectHash] : mapEntry[selectHash] = substyle(select, defaultStyle);
return selectHash in mapEntry ? mapEntry[selectHash] : mapEntry[selectHash] = substyle(select || [], defaultStyle);
};

@@ -34,0 +33,0 @@ };

@@ -34,5 +34,6 @@ 'use strict';

className: _propTypes2.default.string,
classNames: ClassNamesPT
classNames: ClassNamesPT,
innerRef: _propTypes2.default.oneOfType([_propTypes2.default.func, _propTypes2.default.shape({ current: _propTypes2.default.instanceOf(Element) })])
};
var ContextTypes = exports.ContextTypes = (_ContextTypes = {}, _defineProperty(_ContextTypes, ENHANCER_CONTEXT_NAME, _propTypes2.default.func), _defineProperty(_ContextTypes, PROPS_DECORATOR_CONTEXT_NAME, _propTypes2.default.func), _ContextTypes);
{
"name": "substyle",
"version": "6.2.1",
"version": "6.3.0",
"description": "Universal styling for reusable React components",

@@ -9,3 +9,3 @@ "main": "lib/index.js",

"build": "babel src --out-dir lib",
"test": "NODE_ENV=test mocha",
"test": "jest",
"prepublish": "npm run test && npm run clean && npm run build"

@@ -33,3 +33,3 @@ },

"dependencies": {
"hoist-non-react-statics": "^1.2.0",
"hoist-non-react-statics": "^3.1.0",
"invariant": "^2.2.0",

@@ -46,12 +46,13 @@ "lodash": "^4.3.0",

"babel-register": "^6.26.0",
"chai": "^3.5.0",
"enzyme": "^3.1.0",
"enzyme-adapter-react-16": "^1.0.1",
"enzyme": "^3.7.0",
"enzyme-adapter-react-16": "^1.6.0",
"jest": "^23.6.0",
"jsdom": "^9.10.0",
"mocha": "^3.5.0",
"react-addons-test-utils": "^15.6.2",
"react-test-renderer": "^16.0.0",
"rimraf": "^2.6.1",
"sinon": "^3.2.1"
},
"jest": {
"setupTestFrameworkScriptFile": "<rootDir>test/setup.js"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc