Skip to content

Commit

Permalink
refactor: revisit prettier config to be minimal (#2193)
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed Nov 14, 2023
1 parent a836356 commit 9857a67
Show file tree
Hide file tree
Showing 36 changed files with 558 additions and 560 deletions.
4 changes: 2 additions & 2 deletions docs/getting-started/comparison.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ type State = {

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

Expand Down Expand Up @@ -362,7 +362,7 @@ type State = {

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

Expand Down
2 changes: 1 addition & 1 deletion docs/guides/auto-generating-selectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
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
Expand Up @@ -38,8 +38,8 @@ export const useBoundStore = create(
{
name: 'food-storage', // unique name
storage: createJSONStorage(() => hashStorage),
}
)
},
),
)
```

Expand Down
2 changes: 1 addition & 1 deletion docs/guides/initialize-state-with-props.md
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions docs/guides/slices-pattern.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ export const useBoundStore = create(
...createBearSlice(...a),
...createFishSlice(...a),
}),
{ name: 'bound-store' }
)
{ name: 'bound-store' },
),
)
```

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

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

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

export type CounterStoreProviderProps = PropsWithChildren
Expand All @@ -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',
)
}

Expand Down Expand Up @@ -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()
})

Expand Down Expand Up @@ -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()
})

Expand Down
36 changes: 18 additions & 18 deletions docs/guides/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -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>
Expand All @@ -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 })),
}))
})),
)
```

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

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

Expand Down Expand Up @@ -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) => {
Expand All @@ -274,8 +274,8 @@ const useBearStore = create<BearState>()(
bears: 0,
increase: (by) => set((state) => ({ bears: state.bears + by })),
}),
'bear-store'
)
'bear-store',
),
)
```

Expand All @@ -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' {
Expand All @@ -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) => {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
}

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

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

Expand Down
52 changes: 26 additions & 26 deletions docs/integrations/persisting-store-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export const useBearStore = create(
{
name: 'food-storage', // name of the item in the storage (must be unique)
storage: createJSONStorage(() => sessionStorage), // (optional) by default, 'localStorage' is used
}
)
},
),
)
```

Expand Down Expand Up @@ -72,8 +72,8 @@ export const useBoundStore = create(
{
// ...
storage: createJSONStorage(() => AsyncStorage),
}
)
},
),
)
```

Expand All @@ -98,10 +98,10 @@ export const useBoundStore = create(
// ...
partialize: (state) =>
Object.fromEntries(
Object.entries(state).filter(([key]) => !['foo'].includes(key))
Object.entries(state).filter(([key]) => !['foo'].includes(key)),
),
}
)
},
),
)
```

Expand All @@ -117,8 +117,8 @@ export const useBoundStore = create(
{
// ...
partialize: (state) => ({ foo: state.foo }),
}
)
},
),
)
```

Expand Down Expand Up @@ -151,8 +151,8 @@ export const useBoundStore = create(
}
}
},
}
)
},
),
)
```

Expand Down Expand Up @@ -202,8 +202,8 @@ export const useBoundStore = create(

return persistedState
},
}
)
},
),
)
```

Expand Down Expand Up @@ -256,8 +256,8 @@ export const useBoundStore = create(
// ...
merge: (persistedState, currentState) =>
deepMerge(currentState, persistedState),
}
)
},
),
)
```

Expand Down Expand Up @@ -285,8 +285,8 @@ export const useBoundStore = create(
{
// ...
skipHydration: true,
}
)
},
),
)
```

Expand Down Expand Up @@ -473,7 +473,7 @@ import { useState, useEffect } from 'react'

const useStore = <T, F>(
store: (callback: (state: T) => unknown) => unknown,
callback: (state: T) => F
callback: (state: T) => F,
) => {
const result = store(callback) as F
const [data, setData] = useState<F>()
Expand Down Expand Up @@ -505,8 +505,8 @@ export const useBearStore = create(
}),
{
name: 'food-storage',
}
)
},
),
)
```

Expand Down Expand Up @@ -625,8 +625,8 @@ export const useBoundStore = create(
{
name: 'food-storage', // unique name
storage: createJSONStorage(() => storage),
}
)
},
),
)
```

Expand Down Expand Up @@ -673,8 +673,8 @@ export const useBearStore = create<BearState>()(
{
name: 'food-storage',
storage,
}
)
},
),
)
```

Expand Down Expand Up @@ -728,8 +728,8 @@ export const useBearStore = create<MyState>()(
name: 'food-storage', // name of item in the storage (must be unique)
storage: createJSONStorage(() => sessionStorage), // (optional) by default the 'localStorage' is used
partialize: (state) => ({ bears: state.bears }),
}
)
},
),
)
```

Expand Down
Loading

1 comment on commit 9857a67

@vercel
Copy link

@vercel vercel bot commented on 9857a67 Nov 14, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.