-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Labels
[STAGE-2] incomplete implementationRemove this label when implementation is completeRemove this label when implementation is complete[STAGE-2] not fully covered by tests yetRemove this label when tests are verified to cover the implementationRemove this label when tests are verified to cover the implementation[STAGE-2] unresolved discussions leftRemove this label when all critical discussions are resolved on the issueRemove this label when all critical discussions are resolved on the issue[STAGE-3] docs changes not added yetRemove this label when the necessary documentation for the feature / change is addedRemove this label when the necessary documentation for the feature / change is added[STAGE-3] missing 2 reviews for RFC PRsRemove this label when at least 2 core team members reviewed and approved the RFC implementationRemove this label when at least 2 core team members reviewed and approved the RFC implementation
Description
Is your feature request related to a problem?
It would be nice to have have functions in stores be bound to the store object.
Describe the solution you'd like
I think a bind option to useStore would be nice. It could even be true by default because the majority use case for functions in the store is using the store object itself.
This can be used orthogonally with deep and reactive.
import { component$, useStore, $, useTask$ } from '@builder.io/qwik';
export default component$(() => {
const store = useStore({
count: 1,
inc: $(function () {console.log('I have a this:', !!this);this.count++})
}, {bind: true})
return <p>Count: {store.count} <button onClick$={store.inc}>one up</button></p>;
});Describe alternatives you've considered
letting the deserializer do it, but then the function is only bound when it's deserialized.
Additional context
This allows making zustand-like APIs.
UPDATE
See this comment to see how to do it manually, but it would be nice if the optimizer did it.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
[STAGE-2] incomplete implementationRemove this label when implementation is completeRemove this label when implementation is complete[STAGE-2] not fully covered by tests yetRemove this label when tests are verified to cover the implementationRemove this label when tests are verified to cover the implementation[STAGE-2] unresolved discussions leftRemove this label when all critical discussions are resolved on the issueRemove this label when all critical discussions are resolved on the issue[STAGE-3] docs changes not added yetRemove this label when the necessary documentation for the feature / change is addedRemove this label when the necessary documentation for the feature / change is added[STAGE-3] missing 2 reviews for RFC PRsRemove this label when at least 2 core team members reviewed and approved the RFC implementationRemove this label when at least 2 core team members reviewed and approved the RFC implementation
Type
Projects
Status
Released as Stable (STAGE 5)