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

Intelligently deduplicating rules for function values #501

Open
kof opened this issue May 19, 2017 · 1 comment
Open

Intelligently deduplicating rules for function values #501

kof opened this issue May 19, 2017 · 1 comment
Labels
complexity:high Best brains need to talk about it. enhancement No kittens die if we don't do that. idea What if we turn JSS into styled-components?

Comments

@kof
Copy link
Member

kof commented May 19, 2017

In case where a property {width: () => 10} is used for many elements, we currently generate many rules, despite the fact that the value is always the same. We can optimize that.

// Lets say we have rule "a" and rule "b"
// Their initial value is the same.
a.width = 10
b.width = 10

// We can generate one rule and use both classes:
.a, .b {
  width: 10
}

// Now "b" changes:
b.width = 20

// We remove the class "b" from the initial rule:
.a {
  width: 10
}
// We create a new rule with the new value for b:
.b {
  width: 20
}
@kof kof added example They get it when they see it. idea What if we turn JSS into styled-components? enhancement No kittens die if we don't do that. and removed example They get it when they see it. labels May 19, 2017
@kof
Copy link
Member Author

kof commented Jul 2, 2017

I am thinking of a virtual StyleRule concept. When StyleRule is constructed, it is given a virtual: true flag. Flag virtual is true when there has been an exact same rule (host rule) already in the RuleList based on props + values and that rule has function values. The virtual StyleRule will not be rendered, but it's selector will be added to the rule which is rendered, so that it's selector is fully functional for the user but does not has a separate CSS Rule rendered. Once the rule is updated and at least one value doesn't matches the host rule value, rule becomes non-virtual. It removes its selector from the host rule and renders itself into CSSOM.

Most of it can be done outside of StyleRule, for e.g. inside of RuleList.

@kof kof changed the title Intelligently avoid generating too many rules for function values Intelligently deduplicating rules for function values Jul 31, 2017
@kof kof added the complexity:high Best brains need to talk about it. label Aug 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
complexity:high Best brains need to talk about it. enhancement No kittens die if we don't do that. idea What if we turn JSS into styled-components?
Projects
None yet
Development

No branches or pull requests

1 participant