Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: pmndrs/zustand
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v4.4.6
Choose a base ref
...
head repository: pmndrs/zustand
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v4.4.7
Choose a head ref
  • 6 commits
  • 40 files changed
  • 6 contributors

Commits on Nov 14, 2023

  1. 1
    Copy the full SHA
    9857a67 View commit details

Commits on Nov 22, 2023

  1. Update introduction.md (#2208)

    * Update introduction.md
    
    Adds Bun in the installation commands.
    
    * Update docs/getting-started/introduction.md
    
    Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
    
    ---------
    
    Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
    isiagi and dai-shi authored Nov 22, 2023
    1
    Copy the full SHA
    a7b57b2 View commit details

Commits on Nov 24, 2023

  1. Add a warning to readme about React Server Components (#2202)

    * Add a warning to readme about React Server Components
    
    For more information, see #2200
    
    * Use a softer, more succinct, formally worded warning
    
    ---------
    
    Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
    ADTC and dai-shi authored Nov 24, 2023
    1
    Copy the full SHA
    f5561df View commit details

Commits on Nov 27, 2023

  1. fix(vanilla): unexpected null state update behavior (#2213)

    * fix: unexpected null state update behavior
    
    * chore: lint code
    
    * test: add test for setting state to null
    
    ---------
    
    Co-authored-by: wulimao <tao@trlab.com>
    wulimao49 and wulimao authored Nov 27, 2023
    1
    Copy the full SHA
    949b505 View commit details

Commits on Nov 28, 2023

  1. chore(deps): update dev dependencies (#2217)

    * chore(deps): update dev dependencies
    
    * more typescript versions
    
    * downgrade vite 4.5.0
    dai-shi authored Nov 28, 2023
    1
    Copy the full SHA
    15635ab View commit details
  2. 4.4.7

    dai-shi committed Nov 28, 2023
    1
    Copy the full SHA
    50a8677 View commit details
Showing with 1,509 additions and 1,539 deletions.
  1. +2 −2 .github/workflows/test-multiple-versions.yml
  2. +2 −0 .github/workflows/test-old-typescript.yml
  3. +2 −2 docs/getting-started/comparison.md
  4. +1 −3 docs/getting-started/introduction.md
  5. +1 −1 docs/guides/auto-generating-selectors.md
  6. +2 −2 docs/guides/connect-to-state-with-url-hash.md
  7. +1 −1 docs/guides/initialize-state-with-props.md
  8. +2 −2 docs/guides/slices-pattern.md
  9. +6 −6 docs/guides/testing.md
  10. +18 −18 docs/guides/typescript.md
  11. +2 −2 docs/integrations/immer-middleware.md
  12. +26 −26 docs/integrations/persisting-store-data.md
  13. +2 −1 docs/previous-versions/zustand-v3-create-context.md
  14. +27 −28 package.json
  15. +17 −15 readme.md
  16. +7 −7 src/context.ts
  17. +1 −1 src/middleware/combine.ts
  18. +36 −36 src/middleware/devtools.ts
  19. +12 −12 src/middleware/immer.ts
  20. +24 −24 src/middleware/persist.ts
  21. +3 −3 src/middleware/redux.ts
  22. +3 −3 src/middleware/subscribeWithSelector.ts
  23. +11 −11 src/react.ts
  24. +1 −1 src/shallow.ts
  25. +10 −10 src/traditional.ts
  26. +13 −13 src/vanilla.ts
  27. +27 −27 tests/basic.test.tsx
  28. +8 −8 tests/context.test.tsx
  29. +165 −165 tests/devtools.test.tsx
  30. +68 −68 tests/middlewareTypes.test.tsx
  31. +50 −50 tests/persistAsync.test.tsx
  32. +38 −38 tests/persistSync.test.tsx
  33. +10 −9 tests/shallow.test.tsx
  34. +5 −5 tests/ssr.test.tsx
  35. +6 −6 tests/subscribe.test.tsx
  36. +1 −1 tests/test-utils.ts
  37. +3 −3 tests/types.test.tsx
  38. +19 −1 tests/vanilla/basic.test.ts
  39. +13 −13 tests/vanilla/shallow.test.tsx
  40. +864 −915 yarn.lock
4 changes: 2 additions & 2 deletions .github/workflows/test-multiple-versions.yml
Original file line number Diff line number Diff line change
@@ -33,8 +33,8 @@ jobs:
- 18.0.0
- 18.1.0
- 18.2.0
- 18.3.0-canary-0c6348758-20231030
- 0.0.0-experimental-0c6348758-20231030
- 18.3.0-canary-6c7b41da3-20231123
- 0.0.0-experimental-6c7b41da3-20231123
devtools-skip:
- CI-MATRIX-NOSKIP
include:
2 changes: 2 additions & 0 deletions .github/workflows/test-old-typescript.yml
Original file line number Diff line number Diff line change
@@ -13,6 +13,8 @@ jobs:
fail-fast: false
matrix:
typescript:
- 5.3.2
- 5.2.2
- 5.1.6
- 5.0.4
- 4.9.5
4 changes: 2 additions & 2 deletions docs/getting-started/comparison.md
Original file line number Diff line number Diff line change
@@ -326,7 +326,7 @@ type State = {

type Actions = {
updateCount: (
countCallback: (count: State['count']) => State['count']
countCallback: (count: State['count']) => State['count'],
) => void
}

@@ -362,7 +362,7 @@ type State = {

type Actions = {
updateCount: (
countCallback: (count: State['count']) => State['count']
countCallback: (count: State['count']) => State['count'],
) => void
}

4 changes: 1 addition & 3 deletions docs/getting-started/introduction.md
Original file line number Diff line number Diff line change
@@ -33,9 +33,7 @@ Zustand is available as a package on NPM for use:
```bash
# NPM
npm install zustand

# Yarn
yarn add zustand
# Or, use any package manager of your choice.
```

## First create a store
2 changes: 1 addition & 1 deletion docs/guides/auto-generating-selectors.md
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ type WithSelectors<S> = S extends { getState: () => infer T }
: never

const createSelectors = <S extends UseBoundStore<StoreApi<object>>>(
_store: S
_store: S,
) => {
let store = _store as WithSelectors<typeof _store>
store.use = {}
4 changes: 2 additions & 2 deletions docs/guides/connect-to-state-with-url-hash.md
Original file line number Diff line number Diff line change
@@ -38,8 +38,8 @@ export const useBoundStore = create(
{
name: 'food-storage', // unique name
storage: createJSONStorage(() => hashStorage),
}
)
},
),
)
```

2 changes: 1 addition & 1 deletion docs/guides/initialize-state-with-props.md
Original file line number Diff line number Diff line change
@@ -135,7 +135,7 @@ import { useStoreWithEqualityFn } from 'zustand/traditional'

function useBearContext<T>(
selector: (state: BearState) => T,
equalityFn?: (left: T, right: T) => boolean
equalityFn?: (left: T, right: T) => boolean,
): T {
const store = useContext(BearContext)
if (!store) throw new Error('Missing BearContext.Provider in the tree')
4 changes: 2 additions & 2 deletions docs/guides/slices-pattern.md
Original file line number Diff line number Diff line change
@@ -108,8 +108,8 @@ export const useBoundStore = create(
...createBearSlice(...a),
...createFishSlice(...a),
}),
{ name: 'bound-store' }
)
{ name: 'bound-store' },
),
)
```

12 changes: 6 additions & 6 deletions docs/guides/testing.md
Original file line number Diff line number Diff line change
@@ -249,7 +249,7 @@ export default mergeConfig(
environment: 'jsdom',
setupFiles: ['./setup-vitest.ts'],
},
})
}),
)
```

@@ -302,7 +302,7 @@ export const createCounterStore = () => {
}

export const CounterStoreContext = createContext<StoreApi<CounterStore>>(
null as never
null as never,
)

export type CounterStoreProviderProps = PropsWithChildren
@@ -322,13 +322,13 @@ export const CounterStoreProvider = ({
export type UseCounterStoreContextSelector<T> = (store: CounterStore) => T

export const useCounterStoreContext = <T,>(
selector: UseCounterStoreContextSelector<T>
selector: UseCounterStoreContextSelector<T>,
): T => {
const counterStoreContext = useContext(CounterStoreContext)

if (counterStoreContext === undefined) {
throw new Error(
'useCounterStoreContext must be used within CounterStoreProvider'
'useCounterStoreContext must be used within CounterStoreProvider',
)
}

@@ -371,7 +371,7 @@ describe('Counter', () => {

expect(await screen.findByText(/^1$/)).toBeInTheDocument()
expect(
await screen.findByRole('button', { name: /one up/i })
await screen.findByRole('button', { name: /one up/i }),
).toBeInTheDocument()
})

@@ -441,7 +441,7 @@ describe('CounterWithContext', () => {

expect(await screen.findByText(/^1$/)).toBeInTheDocument()
expect(
await screen.findByRole('button', { name: /one up/i })
await screen.findByRole('button', { name: /one up/i }),
).toBeInTheDocument()
})

36 changes: 18 additions & 18 deletions docs/guides/typescript.md
Original file line number Diff line number Diff line change
@@ -99,7 +99,7 @@ Imagine you have a scenario like this:

```ts
declare const withError: <T, E>(
p: Promise<T>
p: Promise<T>,
) => Promise<[error: undefined, value: T] | [error: E, value: undefined]>
declare const doSomething: () => Promise<string>

@@ -113,10 +113,10 @@ Here, `T` is inferred to be a `string` and `E` is inferred to be `unknown`. You
```ts
declare const withError: {
<E>(): <T>(
p: Promise<T>
p: Promise<T>,
) => Promise<[error: undefined, value: T] | [error: E, value: undefined]>
<T, E>(
p: Promise<T>
p: Promise<T>,
): Promise<[error: undefined, value: T] | [error: E, value: undefined]>
}
declare const doSomething: () => Promise<string>
@@ -142,7 +142,7 @@ import { combine } from 'zustand/middleware'
const useBearStore = create(
combine({ bears: 0 }, (set) => ({
increase: (by: number) => set((state) => ({ bears: state.bears + by })),
}))
})),
)
```

@@ -181,9 +181,9 @@ const useBearStore = create<BearState>()(
bears: 0,
increase: (by) => set((state) => ({ bears: state.bears + by })),
}),
{ name: 'bearStore' }
)
)
{ name: 'bearStore' },
),
),
)
```

@@ -204,7 +204,7 @@ const useBearStore = create<BearState>()(
myMiddlewares((set) => ({
bears: 0,
increase: (by) => set((state) => ({ bears: state.bears + by })),
}))
})),
)
```

@@ -245,12 +245,12 @@ type Logger = <
Mcs extends [StoreMutatorIdentifier, unknown][] = [],
>(
f: StateCreator<T, Mps, Mcs>,
name?: string
name?: string,
) => StateCreator<T, Mps, Mcs>

type LoggerImpl = <T extends State>(
f: StateCreator<T, [], []>,
name?: string
name?: string,
) => StateCreator<T, [], []>

const loggerImpl: LoggerImpl = (f, name) => (set, get, store) => {
@@ -274,8 +274,8 @@ const useBearStore = create<BearState>()(
bears: 0,
increase: (by) => set((state) => ({ bears: state.bears + by })),
}),
'bear-store'
)
'bear-store',
),
)
```

@@ -298,7 +298,7 @@ type Foo = <
Mcs extends [StoreMutatorIdentifier, unknown][] = [],
>(
f: StateCreator<T, [...Mps, ['foo', A]], Mcs>,
bar: A
bar: A,
) => StateCreator<T, Mps, [['foo', A], ...Mcs]>

declare module 'zustand' {
@@ -309,7 +309,7 @@ declare module 'zustand' {

type FooImpl = <T extends State, A>(
f: StateCreator<T, [], []>,
bar: A
bar: A,
) => StateCreator<T, [], []>

const fooImpl: FooImpl = (f, bar) => (set, get, _store) => {
@@ -445,11 +445,11 @@ const bearStore = createStore<BearState>()((set) => ({
function useBearStore(): BearState
function useBearStore<T>(
selector: (state: BearState) => T,
equals?: (a: T, b: T) => boolean
equals?: (a: T, b: T) => boolean,
): T
function useBearStore<T>(
selector?: (state: BearState) => T,
equals?: (a: T, b: T) => boolean
equals?: (a: T, b: T) => boolean,
) {
return useStore(bearStore, selector!, equals)
}
@@ -473,12 +473,12 @@ const bearStore = createStore<BearState>()((set) => ({

const createBoundedUseStore = ((store) => (selector, equals) =>
useStore(store, selector as never, equals)) as <S extends StoreApi<unknown>>(
store: S
store: S,
) => {
(): ExtractState<S>
<T>(
selector: (state: ExtractState<S>) => T,
equals?: (a: T, b: T) => boolean
equals?: (a: T, b: T) => boolean,
): T
}

4 changes: 2 additions & 2 deletions docs/integrations/immer-middleware.md
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ export const useCountStore = create<State & Actions>()(
set((state) => {
state.count -= qty
}),
}))
})),
)
```

@@ -99,7 +99,7 @@ export const useTodoStore = create<State & Actions>()(
set((state) => {
state.todos[todoId].done = !state.todos[todoId].done
}),
}))
})),
)
```

Loading