Closed shimaore closed 6 years ago
Hi Stéphane --
Not quite. Any signals dereferenced by code inside the brackets creates a dependency. So <span>{text()}</span>
will update if text()
changes. To make it static you'd have to move the dereference all the way out of the brackets, something like var _text = text(); ... <span>{_text}</span>
.
This is possible because the compiler translates the JSX expression to something like ...
S(() => {
Surplus.content(span, text());
});
... not -- and I think this is what you were thinking -- something like ...
Surplus.content(span, text());
(Surplus.content()
is a runtime utility to set the contents of an element.)
Since the contents of the {...}
expression is wrapped in a lambda which forms the body of a computation, the dereferencing of text()
is captured and is dynamic.
Make sense? -- Adam
Hi Adam,
Oh I see now, it's actually better to use the function call (so: add the parentheses) otherwise the wrapping happens at runtime instead of compile-time.
(I guess I'm as confused as others about the automatic dependency tracking, although it is reminiscent of knockout. Because of the functional approach I was expecting something closer to flyd hence my mistake.)
I definitely need to read the code of S much closer. ☺
If I understand things properly,
Obviously if my understanding is incorrect I'm happy to learn!