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

Optimization: Generate inline ReactElements #139

Open
rauhs opened this issue Dec 14, 2016 · 3 comments
Open

Optimization: Generate inline ReactElements #139

rauhs opened this issue Dec 14, 2016 · 3 comments

Comments

@rauhs
Copy link

rauhs commented Dec 14, 2016

Starting with React 0.14, we can feed React object literals instead of calls to React.createElement:

{ type: 'div', props: { className: 'foo', children:
  [ bar, { type: Baz, props: { }, key: 'baz', ref: null } ]
}, key: null, ref: null }

This would allow some possible speedup. A gotcha is when the ref is set to a string or a potential string. Then they need to go through createElement. Though this method is discouraged nowadays and callbacks should be used instead.

Also see React issue #3228

@r0man
Copy link
Owner

r0man commented Dec 15, 2016

@rauhs I thought about this as well. I think it's also possible in React versions before 0.14, provided the object literals have a key called $$typeof with the symbol Symbol.for("react.element"). Just haven't had a chance to look into this more deeply. Patch welcome! :)

@rauhs
Copy link
Author

rauhs commented Dec 16, 2016

So I've actually been wanting a "sablono light" that does not come with a runtime interpreter. You may have seen my hacks here: https://gist.github.com/rauhs/38b8598c6549f2fe09ad4d257382ec32 (yeah I know, they're ugly :) )

This prompted me to basically rewrite/fork sablono that removes the interpreter and is way less powerful.

I don't actually want to publish a fork of sablono so my question now is basically: Would you be interested in a "sablono.light" namespace living in this repository for users that want this functionality? It still uses much of your code.

I'm away now for 2 weeks but let me dump a gist here:
https://gist.github.com/rauhs/936fff632f42eb627f442b7d988dfc4b

@r0man
Copy link
Owner

r0man commented Dec 16, 2016

@rauhs I'm not sure about this "light" namespace. I think supporting a 3rd way to build React nodes is a bit too much. However, I'm still interested in the object literal approach.

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

No branches or pull requests

2 participants