odoo / owl

OWL: A web framework for structured, dynamic and maintainable applications
https://odoo.github.io/owl/
Other
1.17k stars 350 forks source link

clean up variable scoping semantics #1610

Open sdegueldre opened 7 months ago

sdegueldre commented 7 months ago

Currently we have a few different tools that we use to control variable scoping: Object.create, ctx[isBoundary], capture(ctx), captureExpression, hasSafeContext, and maybe others.

This is in part because we initially wanted to preserve the Python QWeb implementation's semantics with regards to t-set, partly because we wanted to have JS-like ergonomics for lambdas (eg arrow-function event handlers), but in some places these are fundamentally incompatible and it causes some rough edges.

In this playground example, commenting or uncommenting the t-set changes the behavior completely for example.

Slots are essentially lambda functions, and we would want them to close over their rendering context at the point of definition, but capture(ctx) is a poor man's way to do that, since instead of actually closing over the variable bindings, it closes over a frozen copy of the value. The same problem exists with captureExpression: https://github.com/odoo/owl/issues/1451

In the next major version, it would be nice if the templating language's semantics could mirror those of JS, in particular: