Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[rfc] support for signals in lwc templates #82
base: master
Are you sure you want to change the base?
[rfc] support for signals in lwc templates #82
Changes from all commits
c8ceadf
cd00de2
0204bc3
3e67e0c
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see this as orthogonal, especially because for a v1, we will probably just re-render the whole template anyway (similar to the current system). We'd have to implement fine-grained reactivity to change that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, I think the hint of a
.value
in the template, it is certainly the difference. If we were to continue doing what we are doing, we could get far, but because we don't know what is reactive and what's not reactive, I suspect we might have perf challenges.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You know what's reactive, but that doesn't mean you necessarily want fine-grained reactivity at the level of every observable property. Even Solid batches them together in some cases.
Without Signals, I think we can batch at a very coarse level, e.g. for individual items in a
for:each
iteration, and get a lot of bang for our buck.My main point is that I wouldn't sell Signals based on perf. I'd sell it based on DX.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if I bind with
count
?I really did not like to be forced to use
.value
all the time. I recall you have already answered this question but I could not find your answer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if lwc provides
ref
andunref
like vue 3?https://markus.oberlehner.net/blog/vue-3-composition-api-ref-vs-reactive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the problem of not having a hint (e.g.:
.value
), then you have two options:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about formally restricting this, at least in a v1? This could be relaxed later if there are valid use cases for passing down the signal itself.
(I.e. the runtime engine could detect that an object looks like a signal and was passed down wholesale. This might be a breaking change due to false positives on objects that merely look like signals, but it could be done with API versioning.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How? today you do allow passing objects, and non-plain objects as well. Do you plan to just throw if the object has a
.value
and.subscribe
? that seems expensive, for a very little value.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the use case for being able to pass the signal ref instead of
.value
to a child component? Again, as a dev I really did not like to usecount.value
. If there is no use case, I think we could just usecount
. Then the framework can identify that it is a signal based on its type (maybe you could officially make lwc ts first to get errors at build time) and that the child has to react based on.value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are 3 ways to provide stores to a component:
So take your poison. If you have two side by side components that are using the same store provisioned by a parent component, what else can you do other than 3?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if this behavior is configurable?
It is like vue's
watch.prop.deep
, but for signalsI think you have to describe what happens when binding object props to templates. Can I bind the whole object like using
<div>{{position.value}}</div>
? or do I need to use<div>{{position.value.x}}</div>
or would it be<div>{{position.x.value}}</div>
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AllanOricil all that is possible, but not part of this RFC. Remember, this is about the template, and how to use signals in the template, how to create and update signals, that's a different RFC.
As for the specific syntax in the template, you will probably need to do:
<div>{{position.value.x}}</div>
. The.value
is the signal to listen for changes at runtime.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are both solvable with API versioning IMO – if you don't bump your
<apiVersion>
, you don't get signal reactivity magic.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to. If the library implementing the signals can take care of the first point, then we should be fine. Since this RFC doesn't cover that part, we can discuss the details on the next RFC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't you be sure that it is a signal at build time using ts? This would help the engine to do less checks at runtime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AllanOricil No, the compiler compiles one file at a time in isolation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would love to see a rundown of other frameworks' reactivity systems, and if there is anything we can learn from them, or if there is an emerging standard we can rely on, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nolanlawson certainly. I also want to get @wycats involved here.