Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format all files #369

Merged
merged 8 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .babelrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ export default {
'@babel/preset-env',
{
targets: {
ie: 11
ie: 11,
},
loose: true,
modules: cjs ? 'cjs' : false
}
modules: cjs ? 'cjs' : false,
},
],
'@babel/preset-typescript'
'@babel/preset-typescript',
],
plugins: [cjs && ['@babel/transform-modules-commonjs']].filter(Boolean)
plugins: [cjs && ['@babel/transform-modules-commonjs']].filter(Boolean),
}
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:
'node-standard',
'node-esm',
'react-native',
'expo'
'expo',
]
steps:
- name: Checkout repo
Expand Down
1 change: 0 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
Copy link
Member

Choose a reason for hiding this comment

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

It looks like the vast majority of changes are related to this config change. What's the motivation? Just asking in case we can keep this to a less extensive set of changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Staying consistent with the other repos. Since the plan was to eventually unify all their configs by having them use the shareable configs created in reduxjs/redux-toolkit#4138, I thought taking care of line endings/formatting issues in one PR would make things less unpredictable so you guys won't have to deal with a bunch of formatting changes in an unrelated PR in case somebody decides to run Prettier before pushing their changes.

"arrowParens": "avoid"
}
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import filtersReducer from './features/filters/filtersSlice'
const store = configureStore({
reducer: {
todos: todosReducer,
filters: filtersReducer
}
filters: filtersReducer,
},
})

// The thunk middleware was automatically added
Expand Down Expand Up @@ -86,9 +86,9 @@ const store = configureStore({
middleware: getDefaultMiddleware =>
getDefaultMiddleware({
thunk: {
extraArgument: myCustomApiService
}
})
extraArgument: myCustomApiService,
},
}),
})

// later
Expand All @@ -110,10 +110,10 @@ const store = configureStore({
thunk: {
extraArgument: {
api: myCustomApiService,
otherValue: 42
}
}
})
otherValue: 42,
},
},
}),
})

// later
Expand Down Expand Up @@ -188,7 +188,7 @@ const INCREMENT_COUNTER = 'INCREMENT_COUNTER'

function increment() {
return {
type: INCREMENT_COUNTER
type: INCREMENT_COUNTER,
}
}

Expand Down Expand Up @@ -264,7 +264,7 @@ function makeASandwich(forPerson, secretSauce) {
return {
type: 'MAKE_SANDWICH',
forPerson,
secretSauce
secretSauce,
}
}

Expand All @@ -273,14 +273,14 @@ function apologize(fromPerson, toPerson, error) {
type: 'APOLOGIZE',
fromPerson,
toPerson,
error
error,
}
}

function withdrawMoney(amount) {
return {
type: 'WITHDRAW',
amount
amount,
}
}

Expand All @@ -302,7 +302,7 @@ function makeASandwichWithSecretSauce(forPerson) {
return function (dispatch) {
return fetchSecretSauce().then(
sauce => dispatch(makeASandwich(forPerson, sauce)),
error => dispatch(apologize('The Sandwich Shop', forPerson, error))
error => dispatch(apologize('The Sandwich Shop', forPerson, error)),
)
}
}
Expand Down Expand Up @@ -339,16 +339,16 @@ function makeSandwichesForEverybody() {
.then(() =>
Promise.all([
dispatch(makeASandwichWithSecretSauce('Me')),
dispatch(makeASandwichWithSecretSauce('My wife'))
])
dispatch(makeASandwichWithSecretSauce('My wife')),
]),
)
.then(() => dispatch(makeASandwichWithSecretSauce('Our kids')))
.then(() =>
dispatch(
getState().myMoney > 42
? withdrawMoney(42)
: apologize('Me', 'The Sandwich Shop')
)
: apologize('Me', 'The Sandwich Shop'),
),
)
}
}
Expand All @@ -359,7 +359,7 @@ function makeSandwichesForEverybody() {
store
.dispatch(makeSandwichesForEverybody())
.then(() =>
response.send(ReactDOMServer.renderToString(<MyApp store={store} />))
response.send(ReactDOMServer.renderToString(<MyApp store={store} />)),
)

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

export default connect(state => ({
sandwiches: state.sandwiches
sandwiches: state.sandwiches,
}))(SandwichShop)
```

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"cross-env": "^7.0.3",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"prettier": "^2.4.1",
"prettier": "^3.2.5",
"redux": "^5",
"rimraf": "^3.0.2",
"tsup": "7.0.0",
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type {
ThunkAction,
ThunkDispatch,
ThunkActionDispatch,
ThunkMiddleware
ThunkMiddleware,
} from './types'

/** A function that accepts a potential "extra argument" value to be injected later,
Expand All @@ -15,7 +15,7 @@ export type {
function createThunkMiddleware<
State = any,
BasicAction extends Action = AnyAction,
ExtraThunkArg = undefined
ExtraThunkArg = undefined,
>(extraArgument?: ExtraThunkArg) {
// Standard Redux middleware definition pattern:
// See: https://redux.js.org/tutorials/fundamentals/part-4-store#writing-custom-middleware
Expand Down
14 changes: 7 additions & 7 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import type { Action, AnyAction, Middleware } from 'redux'
export interface ThunkDispatch<
State,
ExtraThunkArg,
BasicAction extends Action
BasicAction extends Action,
> {
// 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!):

// 1) The specific thunk function overload
/** Accepts a thunk function, runs it, and returns whatever the thunk itself returns */
<ReturnType>(
thunkAction: ThunkAction<ReturnType, State, ExtraThunkArg, BasicAction>
thunkAction: ThunkAction<ReturnType, State, ExtraThunkArg, BasicAction>,
): ReturnType

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

Expand All @@ -53,11 +53,11 @@ export type ThunkAction<
ReturnType,
State,
ExtraThunkArg,
BasicAction extends Action
BasicAction extends Action,
> = (
dispatch: ThunkDispatch<State, ExtraThunkArg, BasicAction>,
getState: () => State,
extraArgument: ExtraThunkArg
extraArgument: ExtraThunkArg,
) => ReturnType

/**
Expand All @@ -69,7 +69,7 @@ export type ThunkAction<
* @template ActionCreator Thunk action creator to be wrapped
*/
export type ThunkActionDispatch<
ActionCreator extends (...args: any[]) => ThunkAction<any, any, any, any>
ActionCreator extends (...args: any[]) => ThunkAction<any, any, any, any>,
> = (
...args: Parameters<ActionCreator>
) => ReturnType<ReturnType<ActionCreator>>
Expand All @@ -83,7 +83,7 @@ export type ThunkActionDispatch<
export type ThunkMiddleware<
State = any,
BasicAction extends Action = AnyAction,
ExtraThunkArg = undefined
ExtraThunkArg = undefined,
> = Middleware<
ThunkDispatch<State, ExtraThunkArg, BasicAction>,
State,
Expand Down
4 changes: 2 additions & 2 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('thunk middleware', () => {
const doGetState = () => 42
const nextHandler = thunkMiddleware({
dispatch: doDispatch,
getState: doGetState
getState: doGetState,
})

it('must return a function to handle next', () => {
Expand Down Expand Up @@ -90,7 +90,7 @@ describe('thunk middleware', () => {
// @ts-ignore
withExtraArgument(extraArg)({
dispatch: doDispatch,
getState: doGetState
getState: doGetState,
})()((dispatch: any, getState: any, arg: any) => {
expect(dispatch).toBe(doDispatch)
expect(getState).toBe(doGetState)
Expand Down
12 changes: 6 additions & 6 deletions tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { defineConfig } from 'tsup'
export default defineConfig(options => {
const commonOptions: Partial<Options> = {
entry: {
'redux-thunk': 'src/index.ts'
'redux-thunk': 'src/index.ts',
},
...options
...options,
}

return [
Expand All @@ -15,7 +15,7 @@ export default defineConfig(options => {
format: ['esm'],
outExtension: () => ({ js: '.mjs' }),
dts: true,
clean: true
clean: true,
},
// Support Webpack 4 by pointing `"module"` to a file with a `.js` extension
{
Expand All @@ -24,13 +24,13 @@ export default defineConfig(options => {
target: 'es2017',
dts: false,
outExtension: () => ({ js: '.js' }),
entry: { 'redux-thunk.legacy-esm': 'src/index.ts' }
entry: { 'redux-thunk.legacy-esm': 'src/index.ts' },
},
{
...commonOptions,
format: 'cjs',
outDir: './dist/cjs/',
outExtension: () => ({ js: '.cjs' })
}
outExtension: () => ({ js: '.cjs' }),
},
]
})
28 changes: 14 additions & 14 deletions typescript_test/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
ThunkAction,
ThunkActionDispatch,
ThunkDispatch,
ThunkMiddleware
ThunkMiddleware,
} from '../src/index'

export type State = {
Expand All @@ -19,7 +19,7 @@ export type Actions = { type: 'FOO' } | { type: 'BAR'; result: number }
export type ThunkResult<R> = ThunkAction<R, State, undefined, Actions>

export const initialState: State = {
foo: 'foo'
foo: 'foo',
}

export function fakeReducer(state: State = initialState): State {
Expand All @@ -28,7 +28,7 @@ export function fakeReducer(state: State = initialState): State {

export const store = createStore(
fakeReducer,
applyMiddleware(thunk as ThunkMiddleware<State, Actions>)
applyMiddleware(thunk as ThunkMiddleware<State, Actions>),
)

store.dispatch(dispatch => {
Expand Down Expand Up @@ -70,8 +70,8 @@ store.dispatch(testGetState())
const storeThunkArg = createStore(
fakeReducer,
applyMiddleware(
withExtraArgument('bar') as ThunkMiddleware<State, Actions, string>
)
withExtraArgument('bar') as ThunkMiddleware<State, Actions, string>,
),
)
storeThunkArg.dispatch({ type: 'FOO' })

Expand All @@ -85,23 +85,23 @@ storeThunkArg.dispatch((dispatch, getState, extraArg) => {
})

const callDispatchAsync_anyAction = (
dispatch: ThunkDispatch<State, undefined, any>
dispatch: ThunkDispatch<State, undefined, any>,
) => {
const asyncThunk = (): ThunkResult<Promise<void>> => () =>
({} as Promise<void>)
({}) as Promise<void>
dispatch(asyncThunk()).then(() => console.log('done'))
}
const callDispatchAsync_specificActions = (
dispatch: ThunkDispatch<State, undefined, Actions>
dispatch: ThunkDispatch<State, undefined, Actions>,
) => {
const asyncThunk = (): ThunkResult<Promise<void>> => () =>
({} as Promise<void>)
({}) as Promise<void>
dispatch(asyncThunk()).then(() => console.log('done'))
}
const callDispatchAny = (
dispatch: ThunkDispatch<State, undefined, Actions>
dispatch: ThunkDispatch<State, undefined, Actions>,
) => {
const asyncThunk = (): any => () => ({} as Promise<void>)
const asyncThunk = (): any => () => ({}) as Promise<void>
dispatch(asyncThunk()) // result is any
.then(() => console.log('done'))
}
Expand All @@ -127,9 +127,9 @@ const actions: ActionDispatchs = bindActionCreators(
{
anotherThunkAction,
promiseThunkAction,
standardAction
standardAction,
},
store.dispatch
store.dispatch,
)

actions.anotherThunkAction() === 'hello'
Expand All @@ -152,7 +152,7 @@ function testIssue248() {
const dispatch: ThunkDispatch<any, unknown, AnyAction> = undefined as any

function dispatchWrap(
action: Action | ThunkAction<any, any, unknown, AnyAction>
action: Action | ThunkAction<any, any, unknown, AnyAction>,
) {
// Should not have an error here thanks to the extra union overload
dispatch(action)
Expand Down
Loading