Skip to content

Setters not preserved with React.createClass #6023

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

Closed
caub opened this issue Feb 11, 2016 · 3 comments
Closed

Setters not preserved with React.createClass #6023

caub opened this issue Feb 11, 2016 · 3 comments

Comments

@caub
Copy link

caub commented Feb 11, 2016

setters in React.createClass are ignored http://jsfiddle.net/crl/fu06rxw8/3,
but they work with class syntax http://jsfiddle.net/crl/fu06rxw8/4/

Wouldn't it be possible to create the component class from the object given and preserve any setters/getters?

@jimfb
Copy link
Contributor

jimfb commented Feb 12, 2016

Probably not in a remotely performant way. Performance of module initialization (which directly influences initial load time) would be fatal. http://jsperf.com/sdfewfgwasd/2

Going to close this out, because... it's an edge case that people rarely hit, I don't think we can support it in a performant way, and the workaround is to use ES6 classes.

Feel free to continue the discussion on this thread. We can re-open / re-examine if our thinking on this matter changes dramatically.

That said, I am curious to hear about your use case. What are you trying to do?

@jimfb jimfb closed this as completed Feb 12, 2016
@zpao
Copy link
Member

zpao commented Feb 12, 2016

There's some other discussion in #4450 & #2575 which should give more background. I don't think we intend to make any fundamental changes to the way createClass works so it's really unlikely we'd make setters work.

@caub
Copy link
Author

caub commented Feb 12, 2016

Ah ok thanks guys, performance I see, and even through mixins it's not possible?, I didn't manage as well.

@jimfb I'm doing an html 'wysiwyg' editor, and for a few components, it's a bit dirty because they should be updated by many different events (selectionchange, keydown, mousedown), quite frequently (even if throttled). So sometimes I choose to update the position of popovers (div overlays) manually rather, with vanilla js, and put less things in state, sometimes even nothing. (Another example of where I can't use react is this http://jsfiddle.net/crl/ckvstvrk/36/ react is too slow for these sort of things)

I could do something like http://jsfiddle.net/crl/fu06rxw8/6/ but it's not important after all, thanks

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

3 participants