-
-
Notifications
You must be signed in to change notification settings - Fork 399
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
Conversation
// 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
- 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
Ok I am done, please take a look again |
Lets review and merge this one for now, there are 2 issues we need to think how to solve separately. |
|
||
- 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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
packages/jss/src/RuleList.js
Outdated
// 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
onProcessStyle is invoked on each .update, but in this case we only need to do this once, because fn values can't be added
🎉🎉🎉 |
* 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
* 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)
* 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
#682