Skip to content

Commit 720be61

Browse files
author
Henri Beck
committed
Merge branch 'master' into feat/use-cssom-in-default-unit-plugin
* master: Support plugins processing for observables by default (#892) Typed CSSOM values support (#887) Dynamic values full syntax (#878) [jss-plugin-cache] Use WeakMap for cache plugin (#890) # Conflicts: # packages/jss-plugin-syntax-rule-value-function/.size-snapshot.json # packages/jss-preset-default/.size-snapshot.json # packages/jss/.size-snapshot.json # packages/react-jss/.size-snapshot.json
2 parents fd768a7 + 18ed737 commit 720be61

48 files changed

Lines changed: 9465 additions & 1561 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
## Next / 2018-09-16
22

33
- Fix multiple cases where linking CSS rules didn't work (#815, #710, #664)
4+
- Function values and function rules support now fallbacks, media queries, nesting, global styles (#682)
5+
- Added support for Typed CSSOM values
6+
7+
### Breaking changes
8+
9+
- Observables, function values and rules are now standalone packages, not part of the core. They are still part of the default preset though.
10+
- Function values, rules and observables apply plugins by default now, which means they can support all plugin defined syntaxes, but they are also slower by default. To speed them up use `sheet.update(data, {process: false})` for fn values/rules and `jss.use(pluginObservable({process: false}))` when setting up observables plugin. (#682)
411

512
## 9.8.7 / 2018-06-24
613

docs/json-api.md

Lines changed: 12 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -22,72 +22,6 @@ Compiles to:
2222
}
2323
```
2424

25-
## Function values
26-
27-
If you want dynamic behavior for your Style Sheet, you can use functions as a value which return the actual value. If function values returns `null|undefined|false` - property will be removed. Use [sheet.update(data)](./js-api.md#update-function-values) in order to pass the data object. [Sheet option](./js-api.md#create-style-sheet) `link: true` is required for this to function.
28-
29-
```javascript
30-
const styles = {
31-
button: {
32-
color: data => data.color
33-
}
34-
}
35-
```
36-
37-
### Support of "!important"
38-
39-
To use the `!important` modifier with function values, you must use [array syntax](#alternative-syntax-for-space-and-comma-separated-values):
40-
41-
```javascript
42-
const styles = {
43-
button: {
44-
color: data => [[data.color], '!important']
45-
}
46-
}
47-
```
48-
49-
## Function rules
50-
51-
Similar to function values, you can use a function to return a dynamic style object. Use [sheet.update(data)](./js-api.md#update-function-values) in order to pass the data object. Sheet option `link: true` is required for this to function.
52-
53-
```javascript
54-
const styles = {
55-
button: data => ({
56-
display: 'flex',
57-
color: data.color
58-
})
59-
}
60-
```
61-
62-
## Observable values
63-
64-
In order to create highly dynamic animations, you may want to use streams. Take a look at the [tc39 observable proposal](https://github.com/tc39/proposal-observable). Sheet option `link: true` is required for this to function.
65-
66-
```javascript
67-
const styles = {
68-
button: {
69-
color: new Observable(observer => {
70-
observer.next('red')
71-
})
72-
}
73-
}
74-
```
75-
76-
## Observable rules
77-
78-
Similar to observable values, you can declare observable rules. Stream should contain in this case the style object. Sheet option `link: true` is required for this to function.
79-
80-
```javascript
81-
const styles = {
82-
button: new Observable(observer => {
83-
observer.next({
84-
color: 'red',
85-
opacity: 1
86-
})
87-
})
88-
}
89-
```
90-
9125
## Media Queries
9226

9327
```javascript
@@ -421,6 +355,18 @@ Compiles to:
421355
}
422356
```
423357

358+
## Typed CSSOM (Houdini)
359+
360+
Typed CSSOM values are supported. You can learn more about them [here](https://developers.google.com/web/updates/2018/03/cssom) and track the standardization progress [here](https://ishoudinireadyyet.com/). Also make sure you use a [polyfill](https://github.com/csstools/css-typed-om) for browsers without support. It will make most sence when used together with function values and observables for frequent updates.
361+
362+
```javascript
363+
const styles = {
364+
button: {
365+
margin: CSS.px(10)
366+
}
367+
}
368+
```
369+
424370
## Plugins
425371

426372
JSS plugins give you even more features, [read about them](plugins.md).

karma.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports = config => {
2323
'node_modules/raf/polyfill.js',
2424
'./packages/jss/tests/index.js',
2525
'./packages/jss-plugin-syntax-rule-value-function/src/index.test.js',
26-
'./packages/jss-plugin-syntax-rule-value-observable/src/observable.test.js',
26+
'./packages/jss-plugin-syntax-rule-value-observable/src/index.test.js',
2727
'./packages/jss-plugin-syntax-expand/src/index.test.js',
2828
'./packages/jss-plugin-syntax-default-unit/src/index.test.js',
2929
'./packages/jss-plugin-syntax-camel-case/src/index.test.js',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"eslint-config-prettier": "^2.9.0",
7070
"eslint-plugin-flowtype": "^2.29.1",
7171
"expect.js": "^0.3.1",
72-
"flow-bin": "^0.73.0",
72+
"flow-bin": "^0.83.0",
7373
"json-loader": "^0.5.4",
7474
"karma": "^1.3.0",
7575
"karma-benchmark": "^0.6.0",

packages/jss-plugin-cache/.size-snapshot.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
{
22
"dist/jss-plugin-cache.js": {
3-
"bundled": 1700,
4-
"minified": 727,
5-
"gzipped": 411
3+
"bundled": 1058,
4+
"minified": 515,
5+
"gzipped": 330
66
},
77
"dist/jss-plugin-cache.min.js": {
8-
"bundled": 1700,
9-
"minified": 727,
10-
"gzipped": 411
8+
"bundled": 1058,
9+
"minified": 515,
10+
"gzipped": 330
1111
},
1212
"dist/jss-plugin-cache.cjs.js": {
13-
"bundled": 1334,
14-
"minified": 588,
15-
"gzipped": 351
13+
"bundled": 740,
14+
"minified": 368,
15+
"gzipped": 256
1616
},
1717
"dist/jss-plugin-cache.esm.js": {
18-
"bundled": 1252,
19-
"minified": 519,
20-
"gzipped": 300,
18+
"bundled": 658,
19+
"minified": 299,
20+
"gzipped": 213,
2121
"treeshaked": {
2222
"rollup": {
2323
"code": 0,

packages/jss-plugin-cache/readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ in general.
1010

1111
[![Gitter](https://badges.gitter.im/JoinChat.svg)](https://gitter.im/cssinjs/lobby)
1212

13+
## Polyfills
14+
15+
1. This plugin is using a `WeakMap`. If you support browsers which do not support WeakMap, you will have to include a polyfill.
16+
1317
## Caveats
1418

1519
1. Don't use it if you mutate your `styles`.

packages/jss-plugin-cache/src/index.js

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,11 @@
11
// @flow
22
import type {Plugin} from 'jss'
33

4-
/**
5-
* Tiny WeakMap like cache using arrays.
6-
* Required because we have frozen style objects in dev, which are not extensible,
7-
* so we can't put some key into that object.
8-
* Relies on [].indexOf(Object).
9-
*/
10-
class Cache {
11-
keys = []
12-
13-
data = []
14-
15-
get(key) {
16-
const index = this.keys.indexOf(key)
17-
return index === -1 ? null : this.data[index]
18-
}
19-
20-
set(key, value) {
21-
this.keys.push(key)
22-
this.data.push(value)
23-
}
24-
}
25-
264
export default function cachePlugin(): Plugin {
27-
const cache = new Cache()
5+
const cache = new WeakMap()
286

297
function onCreateRule(name, decl, {parent}) {
30-
return parent ? cache.get(parent.rules.raw[name]) : null
8+
return parent ? cache.get(parent.rules.raw[name]) || null : null
319
}
3210

3311
function onProcessRule(rule) {

packages/jss-plugin-syntax-extend/src/index.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,8 @@ describe('jss-plugin-syntax-extend', () => {
334334
beforeEach(() => {
335335
const styles = {
336336
a: data => ({
337-
height: '200px',
338-
extend: data.redContainer
337+
extend: data.redContainer,
338+
height: '200px'
339339
})
340340
}
341341

@@ -350,7 +350,7 @@ describe('jss-plugin-syntax-extend', () => {
350350

351351
it('should have correct output', () => {
352352
expect(sheet.getRule('a')).to.not.be(undefined)
353-
expect(sheet.toString()).to.be('.a-id {\n height: 200px;\n background: red;\n}')
353+
expect(sheet.toString()).to.be('.a-id {\n background: red;\n height: 200px;\n}')
354354
})
355355
})
356356

packages/jss-plugin-syntax-rule-value-function/.size-snapshot.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
{
22
"dist/jss-plugin-syntax-rule-value-function.js": {
3-
"bundled": 2141,
4-
"minified": 824,
5-
"gzipped": 469
3+
"bundled": 2061,
4+
"minified": 735,
5+
"gzipped": 428
66
},
77
"dist/jss-plugin-syntax-rule-value-function.min.js": {
8-
"bundled": 2141,
9-
"minified": 824,
10-
"gzipped": 469
8+
"bundled": 2061,
9+
"minified": 735,
10+
"gzipped": 428
1111
},
1212
"dist/jss-plugin-syntax-rule-value-function.cjs.js": {
13-
"bundled": 1742,
14-
"minified": 734,
15-
"gzipped": 408
13+
"bundled": 1672,
14+
"minified": 631,
15+
"gzipped": 366
1616
},
1717
"dist/jss-plugin-syntax-rule-value-function.esm.js": {
18-
"bundled": 1670,
19-
"minified": 675,
20-
"gzipped": 360,
18+
"bundled": 1594,
19+
"minified": 567,
20+
"gzipped": 319,
2121
"treeshaked": {
2222
"rollup": {
2323
"code": 12,
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# JSS plugin that allows to use functions for dynamic styles
2+
3+
[![Gitter](https://badges.gitter.im/JoinChat.svg)](https://gitter.im/cssinjs/lobby)
4+
5+
If you want dynamic behavior for your Style Sheet, you can use functions as a value which return the actual value or a rule. If function returns `null|undefined|false` - property will be removed. Use [sheet.update(data)](https://github.com/cssinjs/jss/blob/master/docs/js-api.md#update-function-values) in order to pass the data object.
6+
7+
[Sheet option](https://github.com/cssinjs/jss/blob/master/docs/js-api.md#create-style-sheet) `link: true` is required for this to function.
8+
9+
_Plugins are applied by default to function rules or values._
10+
11+
Make sure you read [how to use
12+
plugins](https://github.com/cssinjs/jss/blob/master/docs/setup.md#setup-with-plugins)
13+
in general.
14+
15+
## Function values
16+
17+
```javascript
18+
const styles = {
19+
button: {
20+
color: data => data.color
21+
}
22+
}
23+
24+
const sheet = jss.createStyleSheet(styles, {link: true}).attach()
25+
26+
sheet.update({color: 'red'})
27+
```
28+
29+
```css
30+
.button-1-2-3 {
31+
color: red;
32+
}
33+
```
34+
35+
## Function rules
36+
37+
Similar to function values, you can use a function to return a dynamic style object. Use [sheet.update(data)](https://github.com/cssinjs/jss/blob/master/docs/js-api.md#update-function-values) in order to pass the data object. Sheet option `link: true` is required for this to function.
38+
39+
```javascript
40+
const styles = {
41+
button: data => ({
42+
display: 'flex',
43+
color: data.color
44+
})
45+
}
46+
```
47+
48+
## Support of "!important"
49+
50+
To use the `!important` modifier with function values, you must use [array syntax](https://github.com/cssinjs/jss/blob/master/docs/json-api.md#alternative-syntax-for-space-and-comma-separated-values):
51+
52+
```javascript
53+
const styles = {
54+
button: {
55+
color: data => [[data.color], '!important']
56+
}
57+
}
58+
```
59+
60+
## Demo
61+
62+
[Simple](http://cssinjs.github.io/examples/function-values/index.html)
63+
64+
## Issues
65+
66+
File a bug against [cssinjs/jss prefixed with \[jss-plugin-syntax-rule-value-function\]](https://github.com/cssinjs/jss/issues/new?title=[jss-plugin-syntax-rule-value-function]%20).
67+
68+
## Run tests
69+
70+
```bash
71+
yarn
72+
yarn test
73+
```
74+
75+
## License
76+
77+
MIT

0 commit comments

Comments
 (0)