Live data from Hacker News

React Implementation Notes

facebook.github.io

91–93 of 93 posts

Re: React Implementation Notes

#91
post #36

Earlier quoted context omitted.

What about generators? I've built coroutines based on generators. CSP has been implemented in JS using generators. Not sure why those projects went thru "staggering amount of overhead" to get what we get for free with generators. Please educate.

The main difference is that all of the use cases I mentioned necessarily don't distinguish between calls/functions that may pause, and calls that don't (it's just the semantics of those languages that arbitrary calls might need to pause). So to use generators as a compilation target, every function has to be a generator, and every call a generator instantiation followed by yield*. I actually don't know if that qualif…

Self-reply for posterity. Here's a sketched-out comparison of generators vs. the manual strategy we use in Pyret (this isn't _exactly_ what Pyret generated code looks like, but it's close):

https://www.measurethat.net/Benchmarks/Show/675/0/stack-stra...

As of October 2016, generators are much slower on all browsers I tested.

Re: React Implementation Notes

#92
post #89

Earlier quoted context omitted.

I think dynamic scope can work with setState by allocating a new closure that closes over the dynamic vars, aliasing them into lexical scope of the render function. The problem with React Context is that it bypasses the general solution offered at language layer for a react-specific solution, essentially breaking any code written without prior knowledge of React.

Can you say what changes would be required in React for this to work? I assume that you are asking for parent components to be on the stack when child components render, but that is simply not how React works – you return a description of what you want to render then React calls into the children. How could the parent be on the stack? If you have a concrete suggestion for something we could change in React I'd be hap…

> but that is simply not how React works ... React calls into the children

That's not how function components work, and i can easily imagine how to get lifecycle methods back (including optimizations) on function components

Re: React Implementation Notes

#93
post #89

Earlier quoted context omitted.

Can you say what changes would be required in React for this to work? I assume that you are asking for parent components to be on the stack when child components render, but that is simply not how React works – you return a description of what you want to render then React calls into the children. How could the parent be on the stack? If you have a concrete suggestion for something we could change in React I'd be hap…

> but that is simply not how React works ... React calls into the children That's not how function components work, and i can easily imagine how to get lifecycle methods back (including optimizations) on function components

Please open an issue with more details about the changes you'd like and tag me in it.
Post reply on HN