Skip to content

Commit 228ad17

Browse files
committed
Add cssobj test cases
1 parent ff37653 commit 228ad17

File tree

14 files changed

+140
-8
lines changed

14 files changed

+140
-8
lines changed

Diff for: README.md

+19-8
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,18 @@ Fastest is: styletron
156156
Launch with `npm run bundle`.
157157

158158
```
159-
Size styletron 2.652KB
160-
Size cxs 9.766KB
159+
Size cssobj 10.375KB
160+
Size cssobj-server 7.181KB
161+
Size free-style 8.3KB
162+
Size styletron 2.667KB
163+
Size jss-without-preset 26.183KB
164+
Size glamor 31.421KB
165+
Size cxs 9.366KB
161166
Size fela 13.161KB
162-
Size cxs-optimized 12.668KB
163-
Size jss-without-preset 24.654KB
164-
Size jss 37.04KB
165-
Size glamor 35.436KB
166-
Size aphrodite 18.919KB
167+
Size cxs-optimized 12.268KB
168+
Size jss 37.185KB
169+
Size aphrodite 19.711KB
170+
Size aphrodite-no-important 19.744KB
167171
```
168172

169173
### View generated code
@@ -183,10 +187,17 @@ For all of them, class name is stable between generations if same content. Unles
183187
(classes overload) Doesn't detect identical classes that remain duplicate.
184188
(nested) Manages pseudo-classes and media queries.
185189

190+
#### cssobj
191+
192+
(simple) Doesn't remove a non-used class. Generates class names like `original-name_13otckp1_` (customizable suffix).
193+
(style overload) Different classes with a common style are kept as is.
194+
(classes overload) Doesn't detect identical classes that remain duplicate.
195+
(nested) Manages pseudo-classes and media queries.
196+
186197
#### cxs and cxs-optimized
187198

188199
(simple) Doesn't remove a non-used class. Generates class names like `cxs-4211614354`.
189-
(style overload) Different classes with a common style are kept as is. Minimized CSS.
200+
(style overload) Different classes with a common style are kept as is.
190201
(classes overload) Detects identical classes that are merged.
191202
(nested) Manages pseudo-classes and media queries.
192203

Diff for: package.json

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
"babel-loader": "^6.2.7",
3434
"beautify-benchmark": "^0.2.4",
3535
"benchmark": "^2.1.2",
36+
"cssobj": "^1.0.1",
37+
"cssobj-core": "^1.0.0",
38+
"cssobj-plugin-localize": "^3.0.1",
39+
"cssobj-plugin-gencss": "^2.0.3",
3640
"cxs": "^2.1.0",
3741
"fela": "^4.1.0",
3842
"free-style": "^2.0.0",

Diff for: src/classes-overload-test/cases/cssobj.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// See simple-test for details
2+
import cssobjCore from 'cssobj-core';
3+
import cssobjPluginLocalize from 'cssobj-plugin-localize';
4+
import cssobjPluginGencss from 'cssobj-plugin-gencss';
5+
6+
import { stylesheet, buttonClassNames } from '../styles';
7+
import { renderHtml, renderBody } from '../render';
8+
import { toClasses } from '../../utilities';
9+
10+
export const cssobjCase = (caseName) => {
11+
const cssobj = cssobjCore({
12+
local: true,
13+
plugins: [
14+
cssobjPluginLocalize(),
15+
cssobjPluginGencss({ indent: '', newLine: '' }),
16+
]
17+
});
18+
const cssObject = cssobj(toClasses(stylesheet));
19+
20+
const getButtonClassName = i => cssObject.mapClass(buttonClassNames[i]);
21+
22+
const html = renderBody(caseName, cssObject.mapClass('container'), getButtonClassName);
23+
24+
return renderHtml(cssObject.css, html);
25+
};

Diff for: src/classes-overload-test/cases/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from './aphrodite';
22
export * from './aphrodite-no-important';
3+
export * from './cssobj';
34
export * from './cxs';
45
export * from './cxs-optimized';
56
export * from './fela';

Diff for: src/nested-test/cases/cssobj.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// See simple-test for details
2+
import cssobjCore from 'cssobj-core';
3+
import cssobjPluginLocalize from 'cssobj-plugin-localize';
4+
import cssobjPluginGencss from 'cssobj-plugin-gencss';
5+
6+
import { createStylesheet } from '../styles';
7+
import { renderHtml, renderBody } from '../render';
8+
import { toClasses } from '../../utilities';
9+
10+
export const cssobjCase = (caseName) => {
11+
const cssobj = cssobjCore({
12+
local: true,
13+
plugins: [
14+
cssobjPluginLocalize(),
15+
cssobjPluginGencss({ indent: '\t', newLine: '\n' }),
16+
]
17+
});
18+
const options = { prefixPseudo: true };
19+
const cssObject = cssobj(toClasses(createStylesheet(options)));
20+
21+
const html = renderBody(caseName, cssObject.mapClass('container'), cssObject.mapClass('button'));
22+
23+
return renderHtml(cssObject.css, html);
24+
};

Diff for: src/nested-test/cases/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from './aphrodite';
22
export * from './aphrodite-no-important';
3+
export * from './cssobj';
34
export * from './cxs';
45
export * from './cxs-optimized';
56
export * from './fela';

Diff for: src/simple-test/cases/cssobj.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//import cssobj from 'cssobj'; // In client
2+
// For server-side rendering
3+
import cssobjCore from 'cssobj-core';
4+
import cssobjPluginLocalize from 'cssobj-plugin-localize';
5+
import cssobjPluginGencss from 'cssobj-plugin-gencss';
6+
7+
import { stylesheet } from '../styles';
8+
import { renderHtml, renderBody } from '../render';
9+
import { toClasses } from '../../utilities';
10+
11+
export const cssobjCase = (caseName) => {
12+
const cssobj = cssobjCore({
13+
local: true, // Add suffix to given class names
14+
plugins: [
15+
// order is important
16+
cssobjPluginLocalize({ /*space: '_custom_', localNames: {}*/ }), // Don't customize the output, defaults to random suffix
17+
cssobjPluginGencss({ indent: '\t', newLine: '\n' }),
18+
]
19+
});
20+
const cssObject = cssobj(toClasses(stylesheet));
21+
22+
const html = renderBody(caseName, cssObject.mapClass('container'), cssObject.mapClass('button'));
23+
24+
return renderHtml(cssObject.css, html);
25+
};

Diff for: src/simple-test/cases/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from './aphrodite';
22
export * from './aphrodite-no-important';
3+
export * from './cssobj';
34
export * from './cxs';
45
export * from './cxs-optimized';
56
export * from './fela';

Diff for: src/size-test/cssobj-server.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import cssobjCore from 'cssobj-core';
2+
import cssobjPluginLocalize from 'cssobj-plugin-localize';
3+
import cssobjPluginGencss from 'cssobj-plugin-gencss';

Diff for: src/size-test/cssobj.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import cssobj from 'cssobj';

Diff for: src/size-test/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ const testBundle = (name) => new Promise((resolve, reject) => {
5757
Promise.all([
5858
testBundle('aphrodite'),
5959
testBundle('aphrodite-no-important'),
60+
testBundle('cssobj'),
61+
testBundle('cssobj-server'),
6062
testBundle('cxs'),
6163
testBundle('cxs-optimized'),
6264
testBundle('fela'),

Diff for: src/style-overload-test/cases/cssobj.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// See simple-test for details
2+
import cssobjCore from 'cssobj-core';
3+
import cssobjPluginLocalize from 'cssobj-plugin-localize';
4+
import cssobjPluginGencss from 'cssobj-plugin-gencss';
5+
6+
import { stylesheet, buttonClassNames } from '../styles';
7+
import { renderHtml, renderBody } from '../render';
8+
import { toClasses } from '../../utilities';
9+
10+
export const cssobjCase = (caseName) => {
11+
const cssobj = cssobjCore({
12+
local: true,
13+
plugins: [
14+
cssobjPluginLocalize(),
15+
cssobjPluginGencss({ indent: '', newLine: '' }), // To be fair, reduce size of generated code; still add space after colon and class name.
16+
]
17+
});
18+
const cssObject = cssobj(toClasses(stylesheet));
19+
20+
const getButtonClassName = i => cssObject.mapClass(buttonClassNames[i]);
21+
22+
const html = renderBody(caseName, cssObject.mapClass('container'), getButtonClassName);
23+
24+
return renderHtml(cssObject.css, html);
25+
};

Diff for: src/style-overload-test/cases/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from './aphrodite';
22
export * from './aphrodite-no-important';
3+
export * from './cssobj';
34
export * from './cxs';
45
export * from './cxs-optimized';
56
export * from './fela';

Diff for: src/utilities.js

+8
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,11 @@ export const createOutputDir = (testName) => {
2323
}
2424
return outputDir;
2525
};
26+
27+
export const toClasses = (css) => {
28+
const newCss = {};
29+
Object.keys(css).forEach((className) => {
30+
newCss[`.${className}`] = css[className];
31+
});
32+
return newCss;
33+
};

0 commit comments

Comments
 (0)