Skip to content

Commit 8ab85c9

Browse files
authored
Format all files (#369)
1 parent 38cbdf7 commit 8ab85c9

File tree

12 files changed

+68
-69
lines changed

12 files changed

+68
-69
lines changed

.babelrc.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ export default {
77
'@babel/preset-env',
88
{
99
targets: {
10-
ie: 11
10+
ie: 11,
1111
},
1212
loose: true,
13-
modules: cjs ? 'cjs' : false
14-
}
13+
modules: cjs ? 'cjs' : false,
14+
},
1515
],
16-
'@babel/preset-typescript'
16+
'@babel/preset-typescript',
1717
],
18-
plugins: [cjs && ['@babel/transform-modules-commonjs']].filter(Boolean)
18+
plugins: [cjs && ['@babel/transform-modules-commonjs']].filter(Boolean),
1919
}

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ jobs:
145145
'node-standard',
146146
'node-esm',
147147
'react-native',
148-
'expo'
148+
'expo',
149149
]
150150
steps:
151151
- name: Checkout repo

.prettierrc.json

-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
"semi": false,
33
"singleQuote": true,
44
"tabWidth": 2,
5-
"trailingComma": "none",
65
"arrowParens": "avoid"
76
}

README.md

+20-20
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import filtersReducer from './features/filters/filtersSlice'
2323
const store = configureStore({
2424
reducer: {
2525
todos: todosReducer,
26-
filters: filtersReducer
27-
}
26+
filters: filtersReducer,
27+
},
2828
})
2929

3030
// The thunk middleware was automatically added
@@ -86,9 +86,9 @@ const store = configureStore({
8686
middleware: getDefaultMiddleware =>
8787
getDefaultMiddleware({
8888
thunk: {
89-
extraArgument: myCustomApiService
90-
}
91-
})
89+
extraArgument: myCustomApiService,
90+
},
91+
}),
9292
})
9393

9494
// later
@@ -110,10 +110,10 @@ const store = configureStore({
110110
thunk: {
111111
extraArgument: {
112112
api: myCustomApiService,
113-
otherValue: 42
114-
}
115-
}
116-
})
113+
otherValue: 42,
114+
},
115+
},
116+
}),
117117
})
118118

119119
// later
@@ -188,7 +188,7 @@ const INCREMENT_COUNTER = 'INCREMENT_COUNTER'
188188

189189
function increment() {
190190
return {
191-
type: INCREMENT_COUNTER
191+
type: INCREMENT_COUNTER,
192192
}
193193
}
194194

@@ -264,7 +264,7 @@ function makeASandwich(forPerson, secretSauce) {
264264
return {
265265
type: 'MAKE_SANDWICH',
266266
forPerson,
267-
secretSauce
267+
secretSauce,
268268
}
269269
}
270270

@@ -273,14 +273,14 @@ function apologize(fromPerson, toPerson, error) {
273273
type: 'APOLOGIZE',
274274
fromPerson,
275275
toPerson,
276-
error
276+
error,
277277
}
278278
}
279279

280280
function withdrawMoney(amount) {
281281
return {
282282
type: 'WITHDRAW',
283-
amount
283+
amount,
284284
}
285285
}
286286

@@ -302,7 +302,7 @@ function makeASandwichWithSecretSauce(forPerson) {
302302
return function (dispatch) {
303303
return fetchSecretSauce().then(
304304
sauce => dispatch(makeASandwich(forPerson, sauce)),
305-
error => dispatch(apologize('The Sandwich Shop', forPerson, error))
305+
error => dispatch(apologize('The Sandwich Shop', forPerson, error)),
306306
)
307307
}
308308
}
@@ -339,16 +339,16 @@ function makeSandwichesForEverybody() {
339339
.then(() =>
340340
Promise.all([
341341
dispatch(makeASandwichWithSecretSauce('Me')),
342-
dispatch(makeASandwichWithSecretSauce('My wife'))
343-
])
342+
dispatch(makeASandwichWithSecretSauce('My wife')),
343+
]),
344344
)
345345
.then(() => dispatch(makeASandwichWithSecretSauce('Our kids')))
346346
.then(() =>
347347
dispatch(
348348
getState().myMoney > 42
349349
? withdrawMoney(42)
350-
: apologize('Me', 'The Sandwich Shop')
351-
)
350+
: apologize('Me', 'The Sandwich Shop'),
351+
),
352352
)
353353
}
354354
}
@@ -359,7 +359,7 @@ function makeSandwichesForEverybody() {
359359
store
360360
.dispatch(makeSandwichesForEverybody())
361361
.then(() =>
362-
response.send(ReactDOMServer.renderToString(<MyApp store={store} />))
362+
response.send(ReactDOMServer.renderToString(<MyApp store={store} />)),
363363
)
364364

365365
// I can also dispatch a thunk async action from a component
@@ -385,7 +385,7 @@ class SandwichShop extends Component {
385385
}
386386

387387
export default connect(state => ({
388-
sandwiches: state.sandwiches
388+
sandwiches: state.sandwiches,
389389
}))(SandwichShop)
390390
```
391391

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"cross-env": "^7.0.3",
5555
"eslint": "^7.32.0",
5656
"eslint-config-prettier": "^8.3.0",
57-
"prettier": "^2.4.1",
57+
"prettier": "^3.3.3",
5858
"redux": "^5",
5959
"rimraf": "^3.0.2",
6060
"tsup": "7.0.0",

src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export type {
55
ThunkAction,
66
ThunkActionDispatch,
77
ThunkDispatch,
8-
ThunkMiddleware
8+
ThunkMiddleware,
99
} from './types'
1010

1111
/** A function that accepts a potential "extra argument" value to be injected later,
@@ -14,7 +14,7 @@ export type {
1414
function createThunkMiddleware<
1515
State = any,
1616
BasicAction extends Action = AnyAction,
17-
ExtraThunkArg = undefined
17+
ExtraThunkArg = undefined,
1818
>(extraArgument?: ExtraThunkArg) {
1919
// Standard Redux middleware definition pattern:
2020
// See: https://redux.js.org/tutorials/fundamentals/part-4-store#writing-custom-middleware

src/types.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import type { Action, AnyAction, Middleware } from 'redux'
1414
export interface ThunkDispatch<
1515
State,
1616
ExtraThunkArg,
17-
BasicAction extends Action
17+
BasicAction extends Action,
1818
> {
1919
// When the thunk middleware is added, `store.dispatch` now has three overloads (NOTE: the order here matters for correct behavior and is very fragile - do not reorder these!):
2020

2121
// 1) The specific thunk function overload
2222
/** Accepts a thunk function, runs it, and returns whatever the thunk itself returns */
2323
<ReturnType>(
24-
thunkAction: ThunkAction<ReturnType, State, ExtraThunkArg, BasicAction>
24+
thunkAction: ThunkAction<ReturnType, State, ExtraThunkArg, BasicAction>,
2525
): ReturnType
2626

2727
// 2) The base overload.
@@ -32,7 +32,7 @@ export interface ThunkDispatch<
3232
// with TS inference ( see https://github.com/microsoft/TypeScript/issues/14107 )
3333
/** A union of the other two overloads for TS inference purposes */
3434
<ReturnType, Action extends BasicAction>(
35-
action: Action | ThunkAction<ReturnType, State, ExtraThunkArg, BasicAction>
35+
action: Action | ThunkAction<ReturnType, State, ExtraThunkArg, BasicAction>,
3636
): Action | ReturnType
3737
}
3838

@@ -53,11 +53,11 @@ export type ThunkAction<
5353
ReturnType,
5454
State,
5555
ExtraThunkArg,
56-
BasicAction extends Action
56+
BasicAction extends Action,
5757
> = (
5858
dispatch: ThunkDispatch<State, ExtraThunkArg, BasicAction>,
5959
getState: () => State,
60-
extraArgument: ExtraThunkArg
60+
extraArgument: ExtraThunkArg,
6161
) => ReturnType
6262

6363
/**
@@ -69,7 +69,7 @@ export type ThunkAction<
6969
* @template ActionCreator Thunk action creator to be wrapped
7070
*/
7171
export type ThunkActionDispatch<
72-
ActionCreator extends (...args: any[]) => ThunkAction<any, any, any, any>
72+
ActionCreator extends (...args: any[]) => ThunkAction<any, any, any, any>,
7373
> = (
7474
...args: Parameters<ActionCreator>
7575
) => ReturnType<ReturnType<ActionCreator>>
@@ -83,7 +83,7 @@ export type ThunkActionDispatch<
8383
export type ThunkMiddleware<
8484
State = any,
8585
BasicAction extends Action = AnyAction,
86-
ExtraThunkArg = undefined
86+
ExtraThunkArg = undefined,
8787
> = Middleware<
8888
ThunkDispatch<State, ExtraThunkArg, BasicAction>,
8989
State,

test/index.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ describe('thunk middleware', () => {
55
const doGetState = () => 42
66
const nextHandler = thunkMiddleware({
77
dispatch: doDispatch,
8-
getState: doGetState
8+
getState: doGetState,
99
})
1010

1111
it('must return a function to handle next', () => {
@@ -90,7 +90,7 @@ describe('thunk middleware', () => {
9090
// @ts-ignore
9191
withExtraArgument(extraArg)({
9292
dispatch: doDispatch,
93-
getState: doGetState
93+
getState: doGetState,
9494
})()((dispatch: any, getState: any, arg: any) => {
9595
expect(dispatch).toBe(doDispatch)
9696
expect(getState).toBe(doGetState)

tsup.config.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { defineConfig } from 'tsup'
44
export default defineConfig(options => {
55
const commonOptions: Partial<Options> = {
66
entry: {
7-
'redux-thunk': 'src/index.ts'
7+
'redux-thunk': 'src/index.ts',
88
},
99
tsconfig: 'tsconfig.build.json',
10-
...options
10+
...options,
1111
}
1212

1313
return [
@@ -16,7 +16,7 @@ export default defineConfig(options => {
1616
format: ['esm'],
1717
outExtension: () => ({ js: '.mjs' }),
1818
dts: true,
19-
clean: true
19+
clean: true,
2020
},
2121
// Support Webpack 4 by pointing `"module"` to a file with a `.js` extension
2222
{
@@ -25,13 +25,13 @@ export default defineConfig(options => {
2525
target: 'es2017',
2626
dts: false,
2727
outExtension: () => ({ js: '.js' }),
28-
entry: { 'redux-thunk.legacy-esm': 'src/index.ts' }
28+
entry: { 'redux-thunk.legacy-esm': 'src/index.ts' },
2929
},
3030
{
3131
...commonOptions,
3232
format: 'cjs',
3333
outDir: './dist/cjs/',
34-
outExtension: () => ({ js: '.cjs' })
35-
}
34+
outExtension: () => ({ js: '.cjs' }),
35+
},
3636
]
3737
})

typescript_test/index.test-d.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
ThunkAction,
66
ThunkActionDispatch,
77
ThunkDispatch,
8-
ThunkMiddleware
8+
ThunkMiddleware,
99
} from 'redux-thunk'
1010
import { thunk, withExtraArgument } from 'redux-thunk'
1111

@@ -19,7 +19,7 @@ describe('type tests', () => {
1919
type ThunkResult<R> = ThunkAction<R, State, undefined, Actions>
2020

2121
const initialState: State = {
22-
foo: 'foo'
22+
foo: 'foo',
2323
}
2424

2525
function fakeReducer(state: State = initialState): State {
@@ -28,7 +28,7 @@ describe('type tests', () => {
2828

2929
const store = createStore(
3030
fakeReducer,
31-
applyMiddleware(thunk as ThunkMiddleware<State, Actions>)
31+
applyMiddleware(thunk as ThunkMiddleware<State, Actions>),
3232
)
3333

3434
function anotherThunkAction(): ThunkResult<string> {
@@ -89,7 +89,7 @@ describe('type tests', () => {
8989
const dispatch: ThunkDispatch<any, unknown, AnyAction> = undefined as any
9090

9191
function dispatchWrap(
92-
action: Action | ThunkAction<any, any, unknown, AnyAction>
92+
action: Action | ThunkAction<any, any, unknown, AnyAction>,
9393
) {
9494
// Should not have an error here thanks to the extra union overload
9595
expectTypeOf(dispatch).toBeCallableWith(action)
@@ -100,8 +100,8 @@ describe('type tests', () => {
100100
const storeThunkArg = createStore(
101101
fakeReducer,
102102
applyMiddleware(
103-
withExtraArgument('bar') as ThunkMiddleware<State, Actions, string>
104-
)
103+
withExtraArgument('bar') as ThunkMiddleware<State, Actions, string>,
104+
),
105105
)
106106

107107
expectTypeOf(storeThunkArg.dispatch).toBeCallableWith({ type: 'FOO' })
@@ -123,30 +123,30 @@ describe('type tests', () => {
123123

124124
test('call dispatch async with any action', () => {})
125125
const callDispatchAsync_anyAction = (
126-
dispatch: ThunkDispatch<State, undefined, any>
126+
dispatch: ThunkDispatch<State, undefined, any>,
127127
) => {
128128
const asyncThunk = (): ThunkResult<Promise<void>> => () =>
129-
({} as Promise<void>)
129+
({}) as Promise<void>
130130

131131
expectTypeOf(dispatch).toBeCallableWith(asyncThunk())
132132
}
133133

134134
test('call dispatch async with specific actions', () => {
135135
const callDispatchAsync_specificActions = (
136-
dispatch: ThunkDispatch<State, undefined, Actions>
136+
dispatch: ThunkDispatch<State, undefined, Actions>,
137137
) => {
138138
const asyncThunk = (): ThunkResult<Promise<void>> => () =>
139-
({} as Promise<void>)
139+
({}) as Promise<void>
140140

141141
expectTypeOf(dispatch).toBeCallableWith(asyncThunk())
142142
}
143143
})
144144

145145
test('call dispatch any', () => {
146146
const callDispatchAny = (
147-
dispatch: ThunkDispatch<State, undefined, Actions>
147+
dispatch: ThunkDispatch<State, undefined, Actions>,
148148
) => {
149-
const asyncThunk = (): any => () => ({} as Promise<void>)
149+
const asyncThunk = (): any => () => ({}) as Promise<void>
150150

151151
dispatch(asyncThunk()) // result is any
152152
.then(() => console.log('done'))
@@ -176,9 +176,9 @@ describe('type tests', () => {
176176
{
177177
anotherThunkAction,
178178
promiseThunkAction,
179-
standardAction
179+
standardAction,
180180
},
181-
store.dispatch
181+
store.dispatch,
182182
)
183183

184184
expectTypeOf(actions.anotherThunkAction()).toBeString()

0 commit comments

Comments
 (0)