mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
575db2b4ea7213badc3a0be2b58330a0918091cc
Updates the ReactiveFunction-based codegen from the previous PR to emit memoization code for each scope. This is currently naive and has some bugs, but it gets the idea across. The core logic is straightforward at this point, all the hard work is in earlier passes: * Compute one change variable per scope dependency, eg `const c_0 = $[0] === maxItems` * Generate one `let` binding for each scope output * Generate an if block where the test is if any of the change variables are true (`||` them together) * Generate the consequent block with the original code block, plus statements to save dependencies and outputs to their cache slots * Generate the alternate block to populate the scope outputs from their cached values ## Todos A few things don't quite work yet: * Codegen is designed to avoid emitting variables for temporary values, but that's causing a few values to sort of disappear n the examples, or get emitted twice. There are a variety of ways to achieve this but we'll need to ensure that this category of values gets assigned to a variable and then reference the variable. This is more involved. * Scopes can end up with zero dependencies, in which case we should check that the first output cache is initialized. This one is more straightforward. * If there are early returns, we don't record that they occurred and replay them in the `else` branch for each scope. We know the algorithm though so i'm okay delaying that for now.
Description
Languages
JavaScript
67.1%
TypeScript
29.4%
HTML
1.5%
CSS
1.1%
C++
0.6%
Other
0.2%