-
Notifications
You must be signed in to change notification settings - Fork 11
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
base: main
Are you sure you want to change the base?
Conversation
tests/make/makeStore.t.ts
Outdated
@@ -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*. |
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.
Clean these up, make them comments on the PR instead
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 |
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.
for hiding stuff from consumers, you could use a symbol,
e.g.:
const STATE = Symbol.for("__state__");
// ...
(store as any)[STATE] = true;
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.
Thank you so much for this!
Thanks for the thorough tests.
Looks like you have some tidying to do 💪
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! |
Adding
makeStore
,makeState
, andmakeMemo
functions along with corresponding types and unit tests.makeStore
has an optionalisDeep
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
andmakeMemo
call upon themakeStore
function and when invoked behave as individual Signals and Computeds, respectively.Note: Reads/writes for reactive objects created with
makeState
andmakeMemo
need to be done through access to theirvalue
property - this is by design. However, reactive objects created withmakeStore
allow reads/writes directly on keys of the returned store.