You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
No
Description
The Signals library makes clever usage of the this context to avoid creating extra functions when creating new Signals.
signalFn.set=signalSetFn;// 👈 Depends on 'this'// vssignalFn.set=signalSetFn.bind(node);// or (fastest?)signalFn.set=signalSetFn(node);// 👈 Returns a bound closure
The problem is it's easy to lose the this context by using the function as a value.
constcurrent=signal(0);dataStream.subscribe(current.set);// 👈 Wrong 'this' context leads to obscure errors
This surfaces a minor trade off between performance and correctness.
Microbenchmarks suggest optimal performance would be creating a closure like so -
constsignalSetFn=(node)=>(newValue)=> ...;signalFn.set=signalSetFn(node);// 👈 In the factory function
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
No
Description
The Signals library makes clever usage of the
this
context to avoid creating extra functions when creating new Signals.The problem is it's easy to lose the
this
context by using the function as a value.This surfaces a minor trade off between performance and correctness.
Microbenchmarks suggest optimal performance would be creating a closure like so -
^ https://measurethat.net/Benchmarks/Show/1328/0/bind-vs-closure-declaration
That's what I'd propose.
Alternatively, we should at least add a descriptive error message since this will come up a lot.
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
No response
Please provide the environment you discovered this bug in (run
ng version
)No response
Anything else?
No response
The text was updated successfully, but these errors were encountered: