blakeembrey / free-style

Make CSS easier and more maintainable by using JavaScript
MIT License
707 stars 29 forks source link

Proposal: Change handlers #60

Closed blakeembrey closed 7 years ago

blakeembrey commented 7 years ago

/cc @basarat, @ajoslin, @jkroso

Free-Style 2.0 removed the change event listeners in favour of a simpler changeId++ approach. However, this isn't great for the browser re-parsing styles. I'd like to propose adding handlers (not an event system) that will receive style changes and you can sync up with a <style /> element using insertRule and deleteRule directly.

All you would need to do is propagate this events directly into a <style /> element instead of resetting the entire element.textContent and causing the browser to re-parse and potential FOUC.

jkroso commented 7 years ago

I don't really use change events so I'll count myself out; once my app has rendered once it doesn't define any more styles

ajoslin commented 7 years ago

Sounds way more performant, I'm on board.

blakeembrey commented 7 years ago

All good. It's a backward compatible change (I'll keep changeId), just wanted to get some eyes on it. I'll update the issue when it's implemented 😄

basarat commented 7 years ago

Note to self: Useage in typestyle : https://github.com/typestyle/typestyle/blob/d4de3659c88f348e1c2220cc405aba62c9db4b04/src/internal/typestyle.ts#L87-L99 /cc @notoriousb1t

(I'll keep changeId),

Well be fine then :rose: :heart:

ajoslin commented 7 years ago

Non-breaking change is great to hear.