Skip to content

Commit 707b0d9

Browse files
committed
chore: apply formatting
1 parent a136620 commit 707b0d9

13 files changed

+101
-82
lines changed

packages/vue-redux/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ The following Vue component works as-expected:
3636

3737
```vue
3838
<script setup lang="ts">
39-
import { useSelector, useDispatch } from '@reduxjs/vue-redux'
40-
import { decrement, increment } from './store/counter-slice'
41-
import { RootState } from './store'
39+
import { useSelector, useDispatch } from '@reduxjs/vue-redux'
40+
import { decrement, increment } from './store/counter-slice'
41+
import { RootState } from './store'
4242
43-
const count = useSelector((state: RootState) => state.counter.value)
44-
const dispatch = useDispatch()
43+
const count = useSelector((state: RootState) => state.counter.value)
44+
const dispatch = useDispatch()
4545
</script>
4646
4747
<template>

packages/vue-redux/src/compositions/use-dispatch.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
import { createStoreComposition, useStore as useDefaultStore } from './use-store'
1+
import { ContextKey } from '../provider/context'
2+
import {
3+
createStoreComposition,
4+
useStore as useDefaultStore,
5+
} from './use-store'
6+
import type { VueReduxContextValue } from '../provider/context';
27
import type { Action, Dispatch, UnknownAction } from 'redux'
3-
import type {InjectionKey} from "vue";
4-
import {ContextKey, VueReduxContextValue} from "../provider/context";
8+
import type { InjectionKey } from 'vue'
59

610
/**
711
* Represents a custom composition that provides a dispatch function
@@ -53,7 +57,10 @@ export function createDispatchComposition<
5357
StateType = unknown,
5458
ActionType extends Action = UnknownAction,
5559
>(
56-
context?: InjectionKey<VueReduxContextValue<StateType, ActionType> | null> = ContextKey,
60+
context?: InjectionKey<VueReduxContextValue<
61+
StateType,
62+
ActionType
63+
> | null> = ContextKey,
5764
) {
5865
const useStore =
5966
context === ContextKey ? useDefaultStore : createStoreComposition(context)

packages/vue-redux/src/compositions/use-redux-context.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import {inject} from "vue";
2-
import type {InjectionKey} from "vue";
3-
import {ContextKey, VueReduxContextValue} from "../provider/context";
1+
import { inject } from 'vue'
2+
import { ContextKey } from '../provider/context'
3+
import type { VueReduxContextValue } from '../provider/context';
4+
import type { InjectionKey } from 'vue'
45

56
/**
67
* Composition factory, which creates a `useReduxContext` hook bound to a given context. This is a low-level

packages/vue-redux/src/compositions/use-selector.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import {inject, type InjectionKey, readonly, ref, toRaw, watch} from 'vue'
1+
import { inject, readonly, ref, toRaw, watch } from 'vue'
2+
import { ContextKey } from '../provider/context'
23
import { StoreSymbol } from './provide-store'
3-
import type { StoreContext } from './provide-store'
4-
import type { DeepReadonly, Ref, UnwrapRef} from 'vue'
5-
import type { EqualityFn } from './types'
6-
import {ContextKey, VueReduxContextValue} from "../provider/context";
74
import {
85
createReduxContextComposition,
96
useReduxContext as useDefaultReduxContext,
107
} from './use-redux-context'
8+
import type {DeepReadonly, InjectionKey, Ref, UnwrapRef } from 'vue';
9+
import type { StoreContext } from './provide-store'
10+
import type { EqualityFn } from './types'
11+
import type { VueReduxContextValue } from '../provider/context';
1112

1213
export interface UseSelectorOptions<Selected> {
1314
equalityFn?: EqualityFn<Selected>

packages/vue-redux/src/compositions/use-store.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import {inject} from 'vue'
2-
import type {InjectionKey} from 'vue'
3-
import type { Action, Store } from 'redux'
4-
import {ContextKey, VueReduxContextValue} from "../provider/context";
1+
import { inject } from 'vue'
2+
import { ContextKey } from '../provider/context'
53
import {
64
createReduxContextComposition,
75
useReduxContext as useDefaultReduxContext,
86
} from './use-redux-context'
7+
import type { VueReduxContextValue } from '../provider/context'
8+
import type { InjectionKey } from 'vue'
9+
import type { Action, Store } from 'redux'
910

1011
/**
1112
* Represents a type that extracts the action type from a given Redux store.
@@ -78,13 +79,15 @@ export function createStoreComposition<
7879
StateType = unknown,
7980
ActionType extends Action = Action,
8081
>(
81-
context?: InjectionKey<VueReduxContextValue<StateType, ActionType> | null> = ContextKey,
82+
context?: InjectionKey<VueReduxContextValue<
83+
StateType,
84+
ActionType
85+
> | null> = ContextKey,
8286
) {
8387
const useReduxContext =
8488
context === ContextKey
8589
? useDefaultReduxContext
86-
: // @ts-ignore
87-
createReduxContextComposition(context)
90+
: createReduxContextComposition(context)
8891
const useStore = () => {
8992
const { store } = useReduxContext()
9093
return store
+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import type { Subscription } from '../utils/Subscription'
12
import type { Action, Store, UnknownAction } from 'redux'
2-
import {Subscription} from '../utils/Subscription'
33
import type { ProviderProps } from './Provider'
4-
import {InjectionKey} from "vue";
4+
import type { InjectionKey } from 'vue'
55

66
export interface VueReduxContextValue<
77
SS = any,
@@ -11,4 +11,6 @@ export interface VueReduxContextValue<
1111
subscription: Subscription
1212
}
1313

14-
export const ContextKey = Symbol.for(`vue-redux-context`) as InjectionKey<VueReduxContextValue>
14+
export const ContextKey = Symbol.for(
15+
`vue-redux-context`,
16+
) as InjectionKey<VueReduxContextValue>

packages/vue-redux/src/provider/provider.ts

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { onScopeDispose, provide } from 'vue'
2+
import { createSubscription } from '../utils/Subscription'
3+
import { ContextKey } from './context'
4+
import type { ProviderProps, VueReduxContextValue } from './context';
25
import type { App, InjectionKey } from 'vue'
3-
import type {Action, Store, UnknownAction} from 'redux'
4-
import {ContextKey, ProviderProps, VueReduxContextValue} from "./context";
5-
import {createSubscription, Subscription} from "../utils/Subscription";
6+
import type { Action, Store, UnknownAction } from 'redux'
7+
import type { Subscription} from '../utils/Subscription';
68

79
export interface ProviderProps<
810
A extends Action<string> = UnknownAction,
@@ -22,11 +24,12 @@ export interface ProviderProps<
2224
context?: InjectionKey<VueReduxContextValue<S, A> | null>
2325
}
2426

25-
2627
export function getContext<
2728
A extends Action<string> = UnknownAction,
2829
S = unknown,
29-
>({ store }: Pick<ProviderProps<A, S>, "store">): VueReduxContextValue<S, A> | null {
30+
>({
31+
store,
32+
}: Pick<ProviderProps<A, S>, 'store'>): VueReduxContextValue<S, A> | null {
3033
const subscription = createSubscription(store) as Subscription
3134
subscription.onStateChange = subscription.notifyNestedSubs
3235
subscription.trySubscribe()
@@ -40,26 +43,26 @@ export function getContext<
4043
export function provideStore<
4144
A extends Action<string> = UnknownAction,
4245
S = unknown,
43-
>({store, context}: ProviderProps<A, S>) {
44-
const contextValue = getContext({store})
46+
>({ store, context }: ProviderProps<A, S>) {
47+
const contextValue = getContext({ store })
4548

4649
onScopeDispose(() => {
4750
contextValue.subscription.tryUnsubscribe()
4851
contextValue.subscription.onStateChange = undefined
4952
})
5053

51-
const providerKey = context || ContextKey;
54+
const providerKey = context || ContextKey
5255

5356
provide(providerKey, contextValue)
5457
}
5558

5659
export function provideStoreToApp<
5760
A extends Action<string> = UnknownAction,
5861
S = unknown,
59-
>(app: App, {store, context}: ProviderProps<A, S>) {
60-
const contextValue = getContext({store})
62+
>(app: App, { store, context }: ProviderProps<A, S>) {
63+
const contextValue = getContext({ store })
6164

62-
const providerKey = context || ContextKey;
65+
const providerKey = context || ContextKey
6366

6467
app.provide(providerKey, contextValue)
6568
}

packages/vue-redux/tests/compositions.with-types.test.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {describe, test, expect} from "vitest";
2-
import type { Action, ThunkAction } from '@reduxjs/toolkit'
1+
import { describe, expect, test } from 'vitest'
32
import { configureStore, createAsyncThunk, createSlice } from '@reduxjs/toolkit'
43
import { useDispatch, useSelector, useStore } from '../src'
4+
import type { Action, ThunkAction } from '@reduxjs/toolkit'
55

66
export interface CounterState {
77
counter: number

packages/vue-redux/tests/use-dispatch.spec.tsx

+24-19
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
import {describe, it, expect} from "vitest";
2-
import {defineComponent, h, InjectionKey} from 'vue'
1+
import { describe, expect, it } from 'vitest'
2+
import { defineComponent, h } from 'vue'
3+
import { createStore } from 'redux'
4+
import { render } from '@testing-library/vue'
35
import {
46
createDispatchComposition,
57
provideStore as provideMock,
6-
useDispatch, VueReduxContextValue,
8+
useDispatch
79
} from '../src'
8-
import { createStore } from 'redux'
9-
import {render} from "@testing-library/vue";
10+
import type {
11+
VueReduxContextValue} from '../src';
12+
import type { InjectionKey } from 'vue';
1013

1114
const store = createStore((c: number = 1): number => c + 1)
1215
const store2 = createStore((c: number = 1): number => c + 2)
@@ -16,45 +19,47 @@ describe('Vue', () => {
1619
describe('useDispatch', () => {
1720
it("returns the store's dispatch function", () => {
1821
const Comp = defineComponent(() => {
19-
const dispatch = useDispatch();
22+
const dispatch = useDispatch()
2023
expect(dispatch).toBe(store.dispatch)
2124

22-
return () => null;
25+
return () => null
2326
})
2427

2528
const App = defineComponent(() => {
26-
provideMock({store});
27-
return () => <Comp/>
29+
provideMock({ store })
30+
return () => <Comp />
2831
})
2932

30-
render(<App/>)
33+
render(<App />)
3134
})
3235
})
3336
describe('createDispatchComposition', () => {
3437
it("returns the correct store's dispatch function", () => {
35-
const nestedContext = Symbol.for("mock-redux-store") as InjectionKey<VueReduxContextValue | null>
38+
const nestedContext = Symbol.for(
39+
'mock-redux-store',
40+
) as InjectionKey<VueReduxContextValue | null>
3641
const useCustomDispatch = createDispatchComposition(nestedContext)
3742

3843
const CheckDispatch = defineComponent(() => {
39-
const dispatch = useDispatch();
40-
const customDispatch = useCustomDispatch();
44+
const dispatch = useDispatch()
45+
const customDispatch = useCustomDispatch()
4146
expect(dispatch).toBe(store.dispatch)
4247
expect(customDispatch).toBe(store2.dispatch)
4348

44-
return () => null;
49+
return () => null
4550
})
4651

4752
const InnerApp = defineComponent(() => {
48-
provideMock({store: store2, context: nestedContext});
49-
return () => <CheckDispatch/>
53+
provideMock({ store: store2, context: nestedContext })
54+
return () => <CheckDispatch />
5055
})
5156

5257
const App = defineComponent(() => {
53-
provideMock({store});
54-
return () => <InnerApp/>
58+
provideMock({ store })
59+
return () => <InnerApp />
5560
})
5661

57-
render(<App/>)
62+
render(<App />)
5863
})
5964
})
6065
})

packages/vue-redux/tests/use-redux-context.spec.tsx

+16-18
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import {describe, it, expect, vi} from "vitest";
2-
import {
3-
createReduxContextComposition,
4-
useReduxContext,
5-
} from '../src'
6-
import {defineComponent, h} from "vue";
7-
import type {InjectionKey} from "vue";
8-
import {render} from "@testing-library/vue";
1+
import { describe, expect, it, vi } from 'vitest'
2+
import { defineComponent, h } from 'vue'
3+
import { render } from '@testing-library/vue'
4+
import { createReduxContextComposition, useReduxContext } from '../src'
5+
import type { InjectionKey } from 'vue'
96

107
describe('Vue', () => {
118
describe('compositions', () => {
@@ -14,30 +11,31 @@ describe('Vue', () => {
1411
const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
1512

1613
const App = defineComponent(() => {
17-
useReduxContext();
18-
return () => null;
14+
useReduxContext()
15+
return () => null
1916
})
2017

21-
expect(() => render(<App/>)).toThrow(
18+
expect(() => render(<App />)).toThrow(
2219
/could not find vue-redux context value/,
2320
)
2421
spy.mockRestore()
2522
})
2623
})
2724
describe('createReduxContextHook', () => {
2825
it('throws if component is not wrapped in provider', () => {
29-
const customContext = Symbol.for("testing") as InjectionKey<VueReduxContextValue | null>;
30-
const useCustomReduxContext = createReduxContextComposition(customContext)
26+
const customContext = Symbol.for(
27+
'testing',
28+
) as InjectionKey<VueReduxContextValue | null>
29+
const useCustomReduxContext =
30+
createReduxContextComposition(customContext)
3131
const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
3232

33-
3433
const App = defineComponent(() => {
35-
useCustomReduxContext();
36-
return () => null;
34+
useCustomReduxContext()
35+
return () => null
3736
})
3837

39-
40-
expect(() => render(<App/>)).toThrow(
38+
expect(() => render(<App />)).toThrow(
4139
/could not find vue-redux context value/,
4240
)
4341

packages/vue-redux/tests/use-selector-and-dispatch.test.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('Vue Redux', () => {
3737
const App = defineComponent(() => {
3838
provideStore({ store })
3939

40-
return () => <Comp/>
40+
return () => <Comp />
4141
})
4242

4343
const { getByText } = render(<App />)
@@ -70,10 +70,9 @@ describe('Vue Redux', () => {
7070
const App = defineComponent(() => {
7171
provideStore({ store })
7272

73-
return () => <Comp/>
73+
return () => <Comp />
7474
})
7575

76-
7776
const { getByText } = render(<App />)
7877
const btn = getByText('Count: 0')
7978
expect(btn).toBeInTheDocument()

scripts/generateDocs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const packages = [
1010
name: '@reduxjs/vue-redux',
1111
entryPoints: [resolve(__dirname, '../packages/vue-redux/src/index.ts')],
1212
tsconfig: resolve(__dirname, '../packages/vue-redux/tsconfig.docs.json'),
13-
outputDir: resolve(__dirname, '../docs/reference')
13+
outputDir: resolve(__dirname, '../docs/reference'),
1414
},
1515
]
1616

scripts/publish.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ await publish({
1111
{
1212
name: '@reduxjs/vue-redux',
1313
packageDir: 'packages/vue-redux',
14-
}
14+
},
1515
],
1616
branchConfigs: {
1717
main: {

0 commit comments

Comments
 (0)