Skip to content

Commit 18ed737

Browse files
authored
Support plugins processing for observables by default (#892)
* added fallbacks test to fn rules * only call onChangeValue if plugins: true * enable removing props from fn rules * shorter syntax with coercion * wip full syntax support * restore browsers.json * changelog * move hook call to the core * isProcessed flag explanation * added tests to fn rules * remove media rule as a function test case * added a test for #796, as part of #682 * tests for compose plugin * observables - move documentation to the package - update docs, since plugins don't apply by default - introduce option process: true to the plugin to enable plugins if user wants that * move fn values docs * wording * Added tests for using jss-plugin-syntax-expand with function rules and values * Skip fn values with jss-expand for now * move container rules update to the core * optimize onProcessStyle onProcessStyle is invoked on each .update, but in this case we only need to do this once, because fn values can't be added * put variables in the right scope * changelog * Update changelog.md * process: true always
1 parent 87b9d58 commit 18ed737

7 files changed

Lines changed: 49 additions & 28 deletions

File tree

changelog.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +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)
45
- Added support for Typed CSSOM values
56

67
### Breaking changes
78

89
- Observables, function values and rules are now standalone packages, not part of the core. They are still part of the default preset though.
9-
- Function values and rules apply plugins by default now, which means they are slower by default. To speed them up use `sheet.update(data, {process: false})` (#682)
10-
- Observables will not apply plugins by default now, to make them even faster. If you want them to use plugins, can use an option when using the plugin: `jss.use(pluginObservable({process: true}))` (#682)
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)
1111

1212
## 9.8.7 / 2018-06-24
1313

packages/jss-plugin-syntax-rule-value-observable/src/observable-rules.test.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ describe('jss-plugin-syntax-rule-value-observable: rules', () => {
151151
sheet = jss
152152
.createStyleSheet(
153153
{
154-
div: new Observable(obs => {
154+
a: new Observable(obs => {
155155
obs.next({display: 'block'})
156156
observer = obs
157157
})
@@ -163,28 +163,37 @@ describe('jss-plugin-syntax-rule-value-observable: rules', () => {
163163
observer.next({display: 'inline-block'})
164164

165165
expect(sheet.toString()).to.be(stripIndent`
166-
.div-id {
166+
.a-id {
167167
display: inline-block;
168168
}
169169
`)
170170
})
171171

172172
it('should not process props or values', () => {
173+
jss = create(settings).use(
174+
pluginObservable({process: false}),
175+
pluginDefaultUnit(),
176+
pluginCamelCase()
177+
)
178+
sheet = jss.createStyleSheet(
179+
{
180+
a: new Observable(obs => {
181+
observer = obs
182+
})
183+
},
184+
{link: true}
185+
)
173186
observer.next({marginLeft: 20})
174187

175188
expect(sheet.toString()).to.be(stripIndent`
176-
.div-id {
189+
.a-id {
177190
marginLeft: 20;
178191
}
179192
`)
180193
})
181194

182195
it('should process props and values', () => {
183-
jss = create(settings).use(
184-
pluginObservable({process: true}),
185-
pluginDefaultUnit(),
186-
pluginCamelCase()
187-
)
196+
jss = create(settings).use(pluginObservable(), pluginDefaultUnit(), pluginCamelCase())
188197
sheet = jss.createStyleSheet(
189198
{
190199
a: new Observable(obs => {

packages/jss-plugin-syntax-rule-value-observable/src/observable-values.test.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ describe('jss-plugin-syntax-rule-value-observable: values', () => {
6464
})
6565

6666
it('should not process value', () => {
67+
jss = create(settings).use(pluginObservable({process: false}), pluginDefaultUnit())
68+
sheet = jss.createStyleSheet(
69+
{
70+
a: {
71+
height: new Observable(obs => {
72+
observer = obs
73+
})
74+
}
75+
},
76+
{link: true}
77+
)
78+
6779
observer.next(20)
6880

6981
expect(sheet.toString()).to.be(stripIndent`
@@ -74,7 +86,7 @@ describe('jss-plugin-syntax-rule-value-observable: values', () => {
7486
})
7587

7688
it('should process the value', () => {
77-
jss = create(settings).use(pluginObservable({process: true}), pluginDefaultUnit())
89+
jss = create(settings).use(pluginObservable(), pluginDefaultUnit())
7890
sheet = jss.createStyleSheet(
7991
{
8092
a: {

packages/jss/.size-snapshot.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
{
22
"dist/jss.js": {
3-
"bundled": 54280,
3+
"bundled": 54282,
44
"minified": 20204,
5-
"gzipped": 6074
5+
"gzipped": 6078
66
},
77
"dist/jss.min.js": {
8-
"bundled": 53404,
8+
"bundled": 53406,
99
"minified": 19591,
10-
"gzipped": 5757
10+
"gzipped": 5761
1111
},
1212
"dist/jss.cjs.js": {
13-
"bundled": 48003,
13+
"bundled": 48005,
1414
"minified": 20648,
15-
"gzipped": 5818
15+
"gzipped": 5820
1616
},
1717
"dist/jss.esm.js": {
18-
"bundled": 47546,
18+
"bundled": 47548,
1919
"minified": 20276,
20-
"gzipped": 5732,
20+
"gzipped": 5735,
2121
"treeshaked": {
2222
"rollup": {
2323
"code": 17369,

packages/jss/src/rules/StyleRule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export default class StyleRule implements BaseRule {
7878
if (!force && this.style[name] === value) return this
7979

8080
let newValue = value
81-
if (options && options.process === true) {
81+
if (!options || options.process !== false) {
8282
newValue = this.options.jss.plugins.onChangeValue(value, name, this)
8383
}
8484

packages/jss/tests/integration/plugins.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,13 @@ describe('Integration: plugins', () => {
247247
})
248248

249249
it('should be executed just once', () => {
250-
sheet.getRule('a').prop('color', 'green', {process: true})
250+
sheet.getRule('a').prop('color', 'green')
251251
expect(executed).to.be(1)
252252
})
253253

254254
it('should receive correct arguments', () => {
255255
const rule = sheet.getRule('a')
256-
rule.prop('color', 'green', {process: true})
256+
rule.prop('color', 'green')
257257
expect(receivedValue).to.be('green')
258258
expect(receivedProp).to.be('color')
259259
expect(receivedRule).to.be(rule)
@@ -265,7 +265,7 @@ describe('Integration: plugins', () => {
265265
color: red;
266266
}
267267
`)
268-
sheet.getRule('a').prop('color', 'green', {process: true})
268+
sheet.getRule('a').prop('color', 'green')
269269
expect(sheet.toString()).to.be(stripIndent`
270270
.a-id {
271271
color: green;
@@ -276,7 +276,7 @@ describe('Integration: plugins', () => {
276276
it('should pass the new value to the next hook', () => {
277277
jss.use({onChangeValue: value => `${value}-first`})
278278
jss.use({onChangeValue: value => `${value}-second`})
279-
sheet.getRule('a').prop('color', 'green', {process: true})
279+
sheet.getRule('a').prop('color', 'green')
280280
expect(sheet.toString()).to.be(stripIndent`
281281
.a-id {
282282
color: green-first-second;

packages/jss/tests/integration/rules.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -468,28 +468,28 @@ describe('Integration: rules', () => {
468468
it("should not use null when prop wasn't defined before", () => {
469469
jss.use({onChangeValue: () => null})
470470
const rule = jss.createRule()
471-
rule.prop('abc', 'red', {process: true})
471+
rule.prop('abc', 'red')
472472
expect('abc' in rule.style).to.be(false)
473473
})
474474

475475
it("should not use undefined when prop wasn't defined before", () => {
476476
jss.use({onChangeValue: () => undefined})
477477
const rule = jss.createRule()
478-
rule.prop('abc', 'red', {process: true})
478+
rule.prop('abc', 'red')
479479
expect('abc' in rule.style).to.be(false)
480480
})
481481

482482
it('should use null to remove the prop when it was defined before', () => {
483483
jss.use({onChangeValue: () => null})
484484
const rule = jss.createRule({color: 'red'})
485-
rule.prop('color', 'anything', {process: true})
485+
rule.prop('color', 'anything')
486486
expect('color' in rule.style).to.be(false)
487487
})
488488

489489
it('should use undefined to remove the prop when it was defined before', () => {
490490
jss.use({onChangeValue: () => undefined})
491491
const rule = jss.createRule({color: 'red'})
492-
rule.prop('color', 'anything', {process: true})
492+
rule.prop('color', 'anything')
493493
expect('color' in rule.style).to.be(false)
494494
})
495495
})

0 commit comments

Comments
 (0)