Labs Feedback: @lit-labs/preact-signals #4115
Replies: 7 comments 37 replies
-
I'm getting a 404 on the docs link. |
Beta Was this translation helpful? Give feedback.
-
Thanks for putting this together, looks promising. I just have one question, are there any plans to support deepSignals too? For reference (preactjs/signals#4) |
Beta Was this translation helpful? Give feedback.
-
Is the source anywhere available? |
Beta Was this translation helpful? Give feedback.
-
Yes, really cool, we already use it in production! we did a combination of litlabs context, where the context is the signal |
Beta Was this translation helpful? Give feedback.
-
When passing a signal to a component you need to use
instead of
this should be clearer in the documentation. |
Beta Was this translation helpful? Give feedback.
-
Hi, when using the Simple operations like the following example aren't obvious: const list = signal(['a', 'b']);
return html`<p>The list values are ${watch(list).value.join(', ')}</p>`; // doesn't work as `watch()` returns a directive Especially true when compared to the other return html`<p>The list values are ${list.value.join(', ')}</p>`; // very straightforward! Reading more, I discovered that using const listToString = computed(() => list.value.join(', '));
return html`<p>The list values are ${watch(listToString)}</p>`; // does work! But do I need to create a computed each time I want to use a nested value in a |
Beta Was this translation helpful? Give feedback.
-
ProblemWorking with control flow with the const list = signal([{val: 'a', id: 0}, {val: 'b', id: 1}, {val: 'c', id: 2}]);
export class MyElement extends LitElement {
render() {
return html`
<div>
Things in the list: ${
watch(computed(() => repeat(list.value, item => item.id, (item, index) => html`
<div>${item.val}</div>
<!-- this is inside a computed function, so this does not need another `watch()` to trigger -->
${index !== item.length - 1 ? html`<div class="divider"></div>` : nothing}
`))
}
</div>
<div>
<!-- this ternary needs a computed to trigger recalculation -->
The number of items is ${watch(computed(() => (list.value.length % 1 === 0 ? 'even' : 'odd')))}
</div>
`;
}
}
Proposed SolutionI've got two approaches off the top of my head: Vend a
|
Beta Was this translation helpful? Give feedback.
-
The
@lit-labs/preact-signals
package is a set utilities for using Preact Signals in Lit.SignalWatcher
: a class mixin that makes an element watch all signal accesses during the element's reactive update lifecycle, and triggers an element update when signals change.watch()
: a lit-html directive that accepts a single Signal and renders its value, subscribing to updates and updating the DOM when the signal changes.html
,svg
, andwithWatch()
:html
andsvg
template tags that can be used in place of Lit's default template tags which automatically wraps any signals inwatch()
.withWatch()
applies the auto-watching behavior to any lit-html compatible template tag.We want to collect your feedback on your experiences with
@lit-labs/preact-signals
as we iterate on it according to our Lit Labs process and move the package towards possible graduation or retirement.Please try
@lit-labs/preact-signals
and tell us about your experience. Leave comments with your thoughts; highlight what issues or missing features you're blocked on; give a link to a project that uses it; etc.And so we can have some numbers to look at, you can add reactions to this comment to indicate your experience with this package:
🚀 I have tried this package and it works great. I need it. Ship it!
👍 I have tried this package and it seems like a good idea.
😕 I have tried this package and would use it, but it has serious bugs or missing features.
👀 I am interested, but haven't tried the package yet.
👎 I'm not interested in this package.
Note: other reactions like 😄, 🎉, and ❤️ don't mean anything as part of this scheme. You probably mean, and please use, 🚀, 👍, or 👀.
Beta Was this translation helpful? Give feedback.
All reactions