mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-24 09:25:15 +00:00
56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
|
"use strict";
|
||
|
|
||
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
||
|
|
||
|
Object.defineProperty(exports, "__esModule", {
|
||
|
value: true
|
||
|
});
|
||
|
exports.default = void 0;
|
||
|
|
||
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
||
|
|
||
|
var _merge = _interopRequireDefault(require("./merge"));
|
||
|
|
||
|
function compose() {
|
||
|
for (var _len = arguments.length, styles = new Array(_len), _key = 0; _key < _len; _key++) {
|
||
|
styles[_key] = arguments[_key];
|
||
|
}
|
||
|
|
||
|
var fn = function fn(props) {
|
||
|
return styles.reduce(function (acc, style) {
|
||
|
var output = style(props);
|
||
|
|
||
|
if (output) {
|
||
|
return (0, _merge.default)(acc, output);
|
||
|
}
|
||
|
|
||
|
return acc;
|
||
|
}, {});
|
||
|
}; // Alternative approach that doesn't yield any performance gain.
|
||
|
// const handlers = styles.reduce((acc, style) => {
|
||
|
// style.filterProps.forEach(prop => {
|
||
|
// acc[prop] = style;
|
||
|
// });
|
||
|
// return acc;
|
||
|
// }, {});
|
||
|
// const fn = props => {
|
||
|
// return Object.keys(props).reduce((acc, prop) => {
|
||
|
// if (handlers[prop]) {
|
||
|
// return merge(acc, handlers[prop](props));
|
||
|
// }
|
||
|
// return acc;
|
||
|
// }, {});
|
||
|
// };
|
||
|
|
||
|
|
||
|
fn.propTypes = process.env.NODE_ENV !== 'production' ? styles.reduce(function (acc, style) {
|
||
|
return (0, _extends2.default)(acc, style.propTypes);
|
||
|
}, {}) : {};
|
||
|
fn.filterProps = styles.reduce(function (acc, style) {
|
||
|
return acc.concat(style.filterProps);
|
||
|
}, []);
|
||
|
return fn;
|
||
|
}
|
||
|
|
||
|
var _default = compose;
|
||
|
exports.default = _default;
|