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

Add makeStore, makeState, makeMemo utilities #81

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

EvanCzako
Copy link

Adding makeStore, makeState, and makeMemo functions along with corresponding types and unit tests.

makeStore has an optional isDeep boolean input that can be used to create nested reactivity through recursion. It is false by default, adding only top-level reactivity to passed objects. See implementation and unit tests for explanations on how different types of input keys are handled.

makeState and makeMemo call upon the makeStore function and when invoked behave as individual Signals and Computeds, respectively.

Note: Reads/writes for reactive objects created with makeState and makeMemo need to be done through access to their value property - this is by design. However, reactive objects created with makeStore allow reads/writes directly on keys of the returned store.

@@ -0,0 +1,417 @@
// Note from Evan: For some reason, my VSCode won't appropriately assess the return type on keys of store objects. For example, when the input store has a key of *count: number*, the returned store's key is typed *count: unknown*.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean these up, make them comments on the PR instead

tests/make/makeStore.t.ts Outdated Show resolved Hide resolved
value: new Signal.State(value),
});
// Branding for use in stores
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Don't want to expose brand in types
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for hiding stuff from consumers, you could use a symbol,

e.g.:

const STATE = Symbol.for("__state__");
// ...
(store as any)[STATE] = true;

Copy link
Collaborator

@NullVoxPopuli NullVoxPopuli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for this!
Thanks for the thorough tests.

Looks like you have some tidying to do 💪

@NullVoxPopuli
Copy link
Collaborator

bunch of correctness errors there and the tests don't pass https://github.com/proposal-signals/signal-utils/actions/runs/11098489258/job/31209230519?pr=81 😅

Would be exciting to merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants