-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Generic iterable data for ReactDOMComponent CSS styles #3542
Comments
React CSS in JS presentation by Christopher Chedeau. http://blog.vjeux.com/2014/javascript/react-css-in-js-nationjs.html See the m() function and see this repo https://github.com/Sitebase/cssinjs for an inspiration. I've been using this for a while and it works awesome!
|
@garrrio Persistent data structures like those in Immutable.js, ClojureScript, and Mori allow people to similar things to As far as I can tell, CSS-style-attribute rendering and style-prop reconciliation both simply iterate over style POJOs' keys using |
+1 Please add support for Immutable.js and alike! Problem is indeed is in use of react/src/renderers/dom/shared/CSSPropertyOperations.js Lines 121 to 137 in 4c3e965
Personally run into issue with a computed styles who's fields are expressed via getters. |
Going to count this as part of #3059 as we'll likely support either both or neither. |
Ah, I see; thanks for the response. Since, as syranide had pointed out [https://github.com//issues/3059#issuecomment-87301879], the |
It's true that there's no technical reason they need to be consistent, but it's hard for me to imagine us doing one and not the other. |
Currently, React supports only regular JavaScript objects for
ReactDOMComponent
s' style props, using their enumerated keys:But it would be wonderful if it could also support generic data for CSS styles through, e.g., the iterable interface. That would enable Immutable.js and ClojureScript data structures to be directly used as their styles:
Currently, this necessitates converting the generic data into regular JavaScript style objects for every styled element for every render, which is pretty wasteful.
In general, it's extremely useful to be able to express styles as generic data, especially persistent immutable data structures, in order to let the end user manipulate the data in the application's UI (e.g., for end-user UI themes), to serialize the data, and to dynamically merge and manipulate the data as needed at runtime.
React Native already supports the last sort of thing with merging
StyleSheet
s, but it’s uncertain whether regular React will have it (see #2196), and it'd be even better for serializability and manipulability if generic style data could be used.Potential problems:
{style: [styleObject1, styleObject2]}
standard syntax, used for merging style objects together. Unless that is revised (e.g., by adding aStyleSheet.merge
method and having people use that instead), it may not be possible to also support generic style data in React Native, which might create too great of an API mismatch between React and React Native.Nonetheless, I think generic style data are quite important, and I'm already using them copiously, especially for UI themes.
[Somewhat related to #3059.]
The text was updated successfully, but these errors were encountered: