zustandjs / zustand-slices

A slice utility for Zustand
MIT License
170 stars 8 forks source link

refactor: name duplication detection types #8

Closed grumd closed 5 months ago

grumd commented 5 months ago

Additional thoughts: from the TS perspective, working with an array of configs is difficult because of generics around Value type. An easier approach in terms of TS would be API like this:

withSlices(countSlice).and(textSlice);

Which also means that you can get rid of "createSlice"

  withSlices({
    name: 'count',
    value: 0,
    actions: {
      inc: () => (prev) => prev + 1,
      reset: () => () => 0,
    },
  }).and({
    name: 'text',
    value: 'Hello',
    actions: {
      updateText: (newText: string) => () => newText,
      reset: () => () => 'Hello',
    },
  });

Any pipe-type API like this would be way more robust and easy to write in TS.

But as always, the question is do I want to think typescript-first, or api-first? Or is it possible to prioritize both at the same time?

dai-shi commented 5 months ago

Additional thoughts: from the TS perspective, working with an array of configs is difficult because of generics around Value type. An easier approach in terms of TS would be API like this:

withSlices(countSlice).and(textSlice);

Hmm, I'm not sure if people like it. I'm neutral or a bit negative.

But as always, the question is do I want to think typescript-first, or api-first? Or is it possible to prioritize both at the same time?

Yeah, well, my proposition is Zustand API is API-first (and then we have mutator hacks), and Jotai API is TS-first.

So, for now,

withSlices(countSlice, textSlice);

seems good. But, I can change my mind with user feedback in the future.