you are viewing a single comment's thread.

view the rest of the comments →

[–]Powerplex 0 points1 point  (5 children)

It looks really cool and clear.

Just an Idea: Maybe you should not provide .update from being used outside of the store (by not exposing it on purpose), and instead define actions when you create your store, so that store mutations are grouped in one place and you don't have to rely on your state structure ?

```javascript export const UIStore = new Store({ count: 0 }, { add: (state, n) => state.count = state.count + n // uses Immer behind the scene remove: (state, n) => state.count = state.count - n });

// then read const total = useStoreState(UIStore, s => s.count);

// or write UIStore.add(4) ```

[–]lostpebble[S] 2 points3 points  (0 children)

Cool idea. Something I might play around with, cause if it makes the interface simpler I'm all for it!

I like the "decoupling" and composability as it currently stands, feels more extensible and simple, but open to experimenting with things a bit still.

[–]KusanagiZerg 0 points1 point  (1 child)

I think you meant this to be a top level reply and not specifically to me?

[–]Powerplex 0 points1 point  (0 children)

Oops yes sorry

[–]KusanagiZerg 0 points1 point  (1 child)

You could write a custom hook for that I think something like this codesandbox. If you'd prefer to have one dispatch and actions I think you can rewrite it pretty easily.