forked from robinweser/fela
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
rofrischmann
committed
Jun 22, 2017
1 parent
3b781ec
commit 46f610b
Showing
22 changed files
with
765 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
{ | ||
"presets": [ | ||
["es2015", { "modules": false }], | ||
[ | ||
"es2015", | ||
{ | ||
"modules": false | ||
} | ||
], | ||
"stage-0", | ||
"react" | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"presets": [ | ||
"es2015", | ||
"stage-0", | ||
"react" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2017 Robin Frischmann | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
private: "true", | ||
"name": "babel-plugin-fela-benchmark", | ||
"scripts": { | ||
"bench": "npm run static-extraction-all", | ||
"static-extraction-all": "npm run static-extraction-1 && npm run static-extraction-2 && npm run static-extraction-5 && npm run static-extraction-10 && npm run static-extraction-20", | ||
"static-extraction-1": "VARIATIONS=1 babel-node static-extraction", | ||
"static-extraction-2": "VARIATIONS=2 babel-node static-extraction", | ||
"static-extraction-5": "VARIATIONS=5 babel-node static-extraction", | ||
"static-extraction-10": "VARIATIONS=10 babel-node static-extraction", | ||
"static-extraction-20": "VARIATIONS=20 babel-node static-extraction", | ||
"static-extraction": "babel-node static-extraction" | ||
}, | ||
"dependencies": { | ||
"babel-cli": "^6.18.0", | ||
"babel-core": "^6.18.2", | ||
"babel-eslint": "^7.1.1", | ||
"babel-loader": "^6.2.10", | ||
"babel-preset-node6": "^11.0.0", | ||
"babel-preset-react": "^6.16.0", | ||
"beautify-benchmark": "^0.2.4", | ||
"benchmark": "^2.1.2", | ||
"fela": "^5.0.1", | ||
"fela-tools": "^5.0.1", | ||
"fela-utils": "^5.0.1", | ||
"webpack": "^1.14.0" | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
packages/babel-plugin-fela-benchmark/packages/501/bindings/connectFactory.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
|
||
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; }; | ||
|
||
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; }; }(); | ||
|
||
exports.default = connectFactory; | ||
|
||
var _felaUtils = require('fela-utils'); | ||
|
||
var _generateDisplayName = require('./generateDisplayName'); | ||
|
||
var _generateDisplayName2 = _interopRequireDefault(_generateDisplayName); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
|
||
function _possibleConstructorReturn(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; } | ||
|
||
function _inherits(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; } | ||
|
||
function connectFactory(BaseComponent, createElement, contextTypes) { | ||
return function connect(rules) { | ||
return function (component) { | ||
var EnhancedComponent = function (_BaseComponent) { | ||
_inherits(EnhancedComponent, _BaseComponent); | ||
|
||
function EnhancedComponent() { | ||
_classCallCheck(this, EnhancedComponent); | ||
|
||
return _possibleConstructorReturn(this, (EnhancedComponent.__proto__ || Object.getPrototypeOf(EnhancedComponent)).apply(this, arguments)); | ||
} | ||
|
||
_createClass(EnhancedComponent, [{ | ||
key: 'render', | ||
value: function render() { | ||
var _context = this.context, | ||
renderer = _context.renderer, | ||
theme = _context.theme; | ||
|
||
|
||
var styleProps = _extends({}, this.props, { | ||
theme: theme || {} | ||
}); | ||
|
||
var styles = void 0; | ||
|
||
if (typeof rules === 'function') { | ||
styles = rules(styleProps)(renderer); | ||
|
||
// deprecation warning | ||
if (process.env.NODE_ENV !== 'production' && !this.warnDeprecated) { | ||
/* eslint-disable no-console */ | ||
console.warn('Using a `mapStylesToProps` function with `connect` is deprecated. It will be removed soon. Use a direct `rules` object. See https://github.com/rofrischmann/fela/blob/master/packages/react-fela/docs/connect.md'); | ||
/* eslint-enable no-console */ | ||
this.warnDeprecated = true; | ||
} | ||
} else { | ||
styles = (0, _felaUtils.objectReduce)(rules, function (styleMap, rule, name) { | ||
styleMap[name] = renderer.renderRule(rule, styleProps); | ||
return styleMap; | ||
}, {}); | ||
} | ||
|
||
return createElement(component, _extends({}, this.props, { | ||
styles: styles | ||
})); | ||
} | ||
}]); | ||
|
||
return EnhancedComponent; | ||
}(BaseComponent); | ||
|
||
EnhancedComponent.displayName = (0, _generateDisplayName2.default)(component); | ||
|
||
|
||
if (contextTypes) { | ||
EnhancedComponent.contextTypes = _extends({}, component.contextTypes, contextTypes); | ||
} | ||
|
||
return EnhancedComponent; | ||
}; | ||
}; | ||
} |
103 changes: 103 additions & 0 deletions
103
packages/babel-plugin-fela-benchmark/packages/501/bindings/createComponentFactory.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
|
||
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; }; | ||
|
||
exports.default = createComponentFactory; | ||
|
||
var _felaUtils = require('fela-utils'); | ||
|
||
var _combineRules = require('../combineRules'); | ||
|
||
var _combineRules2 = _interopRequireDefault(_combineRules); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
|
||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
|
||
function createComponentFactory(createElement, contextTypes) { | ||
return function createComponent(rule) { | ||
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'div'; | ||
var passThroughProps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; | ||
|
||
var displayName = rule.name ? rule.name : 'FelaComponent'; | ||
|
||
var FelaComponent = function FelaComponent(_ref, _ref2) { | ||
var renderer = _ref2.renderer, | ||
theme = _ref2.theme; | ||
|
||
var children = _ref.children, | ||
_felaRule = _ref._felaRule, | ||
_ref$passThrough = _ref.passThrough, | ||
passThrough = _ref$passThrough === undefined ? [] : _ref$passThrough, | ||
ruleProps = _objectWithoutProperties(_ref, ['children', '_felaRule', 'passThrough']); | ||
|
||
if (!renderer) { | ||
throw new Error("createComponent() can't render styles without the renderer in the context. Missing react-fela's <Provider /> at the app root?"); | ||
} | ||
|
||
var combinedRule = _felaRule ? (0, _combineRules2.default)(rule, _felaRule) : rule; | ||
|
||
// improve developer experience with monolithic renderer | ||
if (renderer.prettySelectors) { | ||
var componentName = typeof type === 'string' ? type : type.displayName || type.name || ''; | ||
|
||
combinedRule.selectorPrefix = displayName + '_' + componentName + '__'; | ||
} | ||
|
||
// compose passThrough props from arrays or functions | ||
var resolvedPassThrough = [].concat(_toConsumableArray((0, _felaUtils.resolvePassThrough)(passThroughProps, ruleProps)), _toConsumableArray((0, _felaUtils.resolvePassThrough)(passThrough, ruleProps))); | ||
|
||
// if the component renders into another Fela component | ||
// we pass down the combinedRule as well as both | ||
if (type._isFelaComponent) { | ||
return createElement(type, _extends({ | ||
_felaRule: combinedRule, | ||
passThrough: resolvedPassThrough | ||
}, ruleProps), children); | ||
} | ||
|
||
var componentProps = (0, _felaUtils.extractPassThroughProps)(resolvedPassThrough, ruleProps); | ||
|
||
ruleProps.theme = theme || {}; | ||
|
||
// fela-native support | ||
if (renderer.isNativeRenderer) { | ||
var felaStyle = renderer.renderRule(combinedRule, ruleProps); | ||
componentProps.style = ruleProps.style ? [ruleProps.style, felaStyle] : felaStyle; | ||
} else { | ||
if (ruleProps.style) { | ||
componentProps.style = ruleProps.style; | ||
} | ||
var cls = ruleProps.className ? ruleProps.className + ' ' : ''; | ||
componentProps.className = cls + renderer.renderRule(combinedRule, ruleProps); | ||
} | ||
|
||
if (ruleProps.id) { | ||
componentProps.id = ruleProps.id; | ||
} | ||
|
||
if (ruleProps.innerRef) { | ||
componentProps.ref = ruleProps.innerRef; | ||
} | ||
|
||
var customType = ruleProps.is || type; | ||
return createElement(customType, componentProps, children); | ||
}; | ||
|
||
if (contextTypes) { | ||
FelaComponent.contextTypes = contextTypes; | ||
} | ||
|
||
// use the rule name as display name to better debug with react inspector | ||
FelaComponent.displayName = displayName; | ||
FelaComponent._isFelaComponent = true; | ||
|
||
return FelaComponent; | ||
}; | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/babel-plugin-fela-benchmark/packages/501/bindings/generateDisplayName.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = generateDisplayName; | ||
function generateDisplayName(component) { | ||
var displayName = component.displayName || component.name; | ||
|
||
if (displayName) { | ||
return 'Fela' + displayName; | ||
} | ||
|
||
return 'ConnectedFelaComponent'; | ||
} |
26 changes: 26 additions & 0 deletions
26
packages/babel-plugin-fela-benchmark/packages/501/combineRules.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = combineRules; | ||
|
||
var _assignStyle = require('css-in-js-utils/lib/assignStyle'); | ||
|
||
var _assignStyle2 = _interopRequireDefault(_assignStyle); | ||
|
||
var _felaUtils = require('fela-utils'); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
function combineRules() { | ||
for (var _len = arguments.length, rules = Array(_len), _key = 0; _key < _len; _key++) { | ||
rules[_key] = arguments[_key]; | ||
} | ||
|
||
return function (props) { | ||
return (0, _felaUtils.arrayReduce)(rules, function (style, rule) { | ||
return (0, _assignStyle2.default)(style, rule(props)); | ||
}, {}); | ||
}; | ||
} |
Oops, something went wrong.