Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic values full syntax #878

Merged
merged 23 commits into from
Oct 14, 2018
Merged

Dynamic values full syntax #878

merged 23 commits into from
Oct 14, 2018

Conversation

kof
Copy link
Member

@kof kof commented Oct 9, 2018

@kof kof requested review from TrySound and HenriBeck October 9, 2018 02:04
@kof kof changed the title Dynamic values full syntax [WIP] Dynamic values full syntax Oct 9, 2018
// We need to run the plugins in case style relies on syntax plugins.
const process = options ? options.process : true
if (process) {
styleRule.options.jss.plugins.onProcessStyle(styleRule.style, styleRule, sheet)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't really like this here, that api was supposed to be private, but I haven't found a way around so far.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't this be moved into the core and then diff it against the previous style object and only update the properties which are needed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I thought we would go with the route of fastValue((props) => props.color) to make fast function values?

Copy link
Member Author

@kof kof Oct 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strict comparison of previous and current style reference before the hook and after might actually be a good idea! Gonna try this!

fastValue we can still add as a separate feature later on, I think we can skip this for now, just because we still have observables for "fast by default" and its not clear if anyone actually using function values as "fast by default" with frequent updates besides of my demos.

Copy link
Member Author

@kof kof Oct 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also sheet.update(data, {process: false}) is an equevalent, so we might not need fastValue() at all

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also make a shallow comparison right?

Also what do you think of only supporting fn values as fast and not fn rules?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regular updates with process: true is not literally slow, its just with more overhead, it is still very fast. I think the only use case that might want that is animations. In that case, it shouldn't be hard to set that option, also I still don't know if anyone using it that way, so I would just wait to see if we learn more about such cases.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also make a shallow comparison right?

Yeah, can be done if needed, I think we only need to check style references currently.

Also what do you think of only supporting fn values as fast and not fn rules?

The problem is that values with jss-expand can be complex too, for e.g. margin: {top, left}, so you will have a painful inconsistency if you make them fast by default.

Copy link
Member

@HenriBeck HenriBeck Oct 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, not make them fast by default but instead only allowing 'fast' functions as function values.

Copy link
Member Author

@kof kof Oct 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thing, no? margin: () => ({top, left})

@@ -127,16 +138,36 @@ export default class RuleList {
/**
* Update the function values with a new data.
*/
update: Update = (name, data) => {
update(...args: UpdateArguments): void {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previous implementation was generating arrow method, which transpiles to a less performant inlined function in constructor

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@kof kof changed the title [WIP] Dynamic values full syntax Dynamic values full syntax Oct 11, 2018
@kof
Copy link
Member Author

kof commented Oct 11, 2018

Ok I am done, please take a look again

@kof
Copy link
Member Author

kof commented Oct 11, 2018

Lets review and merge this one for now, there are 2 issues we need to think how to solve separately.

@kof kof mentioned this pull request Oct 12, 2018

- Observables, function values and rules are now standalone packages, not part of the core. They are still part of the default preset though.
- 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)
- 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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const styleRule: StyleRule = (rule: any)
const {style} = styleRule

plugins.onUpdate(data, rule, sheet, options)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we maybe return the new style from the update hook? Seems to me a little bit cleaner.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dunno, onUpdate doesn't mean onUpdateStyles, it means user called .update(), so not sure what would be a good return there, thats why I didn't return anything

// We need to run the plugins in case new `style` relies on syntax plugins.
plugins.onProcessStyle(styleRule.style, styleRule, sheet)
// Update, remove and add props.
let nextValue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you initialize them here? can't we just use const inside the for loop?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do, I was thinking we should avoid creating more variables in hot places to reduce garbage collection, but on the other hand, transpiled variable will be hoisted anyways, so there is no difference and we can do it in a more readable way

kof added 3 commits October 14, 2018 21:20
onProcessStyle is invoked on each .update, but in this case we only need to do this once, because fn values can't be added
@kof kof merged commit 92a53e4 into master Oct 14, 2018
@kof
Copy link
Member Author

kof commented Oct 14, 2018

🎉🎉🎉

HenriBeck pushed a commit that referenced this pull request Oct 16, 2018
* 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
HenriBeck pushed a commit that referenced this pull request Oct 22, 2018
* origin/add-ts-typings:
  Scoped keyframes (#888)
  Update readme.md (#897)
  Use CSSTOM in default unit plugin (#893)
  Added .nvmrc (#896)
  [WIP] DONT MERGE Fix ci (#895)
  Update ci (#894)
  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)
bhupinderbola pushed a commit to bhupinderbola/jss that referenced this pull request Sep 17, 2019
* 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 cssinjs#796, as part of cssinjs#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants