Skip to content
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

[Content]:Use specific examples to illustrate when Stores should be used instead of signals. #968

Open
huangsheng7271 opened this issue Nov 29, 2024 · 5 comments
Labels
good first issue Good for newcomers help wanted Looking for assistance on this issue planned Features or content that are planned but not yet in progress.

Comments

@huangsheng7271
Copy link

📚 Subject area/topic

/concepts/stores.mdx

📋 Page(s) affected (or suggested, for new content)

The document says that Stores are very useful when handling complex states, but I feel that signals can also handle it. The document only mentions the usage of Stores. I think specific examples should be used to illustrate in which scenarios using Stores is a better choice than signals.

📋 Description of content that is out-of-date or incorrect

The document says that Stores are very useful when handling complex states, but I feel that signals can also handle it. The document only mentions the usage of Stores. I think specific examples should be used to illustrate in which scenarios using Stores is a better choice than signals.

🖥️ Reproduction in StackBlitz (if reporting incorrect content or code samples)

No response

@huangsheng7271 huangsheng7271 added the pending review Awaiting review by team members. label Nov 29, 2024
@LadyBluenotes LadyBluenotes added help wanted Looking for assistance on this issue and removed pending review Awaiting review by team members. labels Dec 1, 2024
@LadyBluenotes LadyBluenotes removed their assignment Dec 1, 2024
@brenelz
Copy link
Collaborator

brenelz commented Dec 17, 2024

I feel almost as soon as you have nested objects you'd want to use a store, but not sure what others mental model for using stores vs signals is

@atilafassina
Copy link
Member

atilafassina commented Dec 20, 2024

@brenelz

I feel almost as soon as you have nested objects you'd want to use a store, but not sure what others mental model for using stores vs signals is

Does it need to be nested? Any complex type would do (arrays or objects) nested or not.
If your state has more than 1 value, it's a store.

e.g.:

const [user, setUser] = createSignal("brenelz")

vs

const [user, setUser] = createStore( { id: "rec-123", handler: "brenelz" })

suggested action item

  • Add a note that Stores are recommended for any kind of complex type objects

@atilafassina atilafassina added good first issue Good for newcomers planned Features or content that are planned but not yet in progress. labels Dec 20, 2024
@brenelz
Copy link
Collaborator

brenelz commented Dec 20, 2024

@atilafassina yeah stores work in that case too but if its just one flattened object I might still use a signal. Not sure if thats ideal tho

@atilafassina
Copy link
Member

@brenelz it depends on how it's updated and where.

the problem of having an object or array in a signal is that every time you update a single value, the whole thing gets recreated, so we lose fine-grained reactivity.

maybe in a few use-cases that's ok, but I find that more often than not, I want my updates to be as granular as possible.

@brenelz
Copy link
Collaborator

brenelz commented Dec 21, 2024

@atilafassina yeah thats a fair point. I should probably use stores more often then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Looking for assistance on this issue planned Features or content that are planned but not yet in progress.
Projects
None yet
Development

No branches or pull requests

4 participants