UNPKG

1.69 kBJavaScriptView Raw
1Object.defineProperty(exports, "__esModule", {
2 value: true
3});
4exports['default'] = separateStyles;
5
6var _object = require('object.assign');
7
8var _object2 = _interopRequireDefault(_object);
9
10var _has = require('has');
11
12var _has2 = _interopRequireDefault(_has);
13
14function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
15
16// This function takes the array of styles and separates them into styles that
17// are handled by Aphrodite and inline styles.
18function separateStyles(stylesArray) {
19 var aphroditeStyles = [];
20
21 // Since determining if an Object is empty requires collecting all of its
22 // keys, and we want the best performance in this code because we are in the
23 // render path, we are going to do a little bookkeeping ourselves.
24 var hasInlineStyles = false;
25 var inlineStyles = {};
26
27 // This is run on potentially every node in the tree when rendering, where
28 // performance is critical. Normally we would prefer using `forEach`, but
29 // old-fashioned for loops are faster so that's what we have chosen here.
30 for (var i = 0; i < stylesArray.length; i += 1) {
31 var style = stylesArray[i];
32
33 // If this style is falsey, we just want to disregard it. This allows for
34 // syntax like:
35 //
36 // css(isFoo && styles.foo)
37 if (style) {
38 if ((0, _has2['default'])(style, '_name') && (0, _has2['default'])(style, '_definition')) {
39 aphroditeStyles.push(style);
40 } else {
41 (0, _object2['default'])(inlineStyles, style);
42 hasInlineStyles = true;
43 }
44 }
45 }
46
47 return {
48 aphroditeStyles: aphroditeStyles,
49 hasInlineStyles: hasInlineStyles,
50 inlineStyles: inlineStyles
51 };
52}
\No newline at end of file