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

Add extraThunkArgument to configureStore options #180

Closed
jednano opened this issue Aug 28, 2019 · 2 comments
Closed

Add extraThunkArgument to configureStore options #180

jednano opened this issue Aug 28, 2019 · 2 comments

Comments

@jednano
Copy link

jednano commented Aug 28, 2019

Related to #113, I would love the ability to provide an extra thunk argument via an extraThunkArgument option to configureStore.

const extraThunkArgument = { foo: 'bar' }
const store = configureStore<RootState, RootActions, typeof extraThunkArgument>({
  reducer: rootReducer,
  extraThunkArgument, 
})

The result of the thunk should be of the following type:

ThunkMiddleware<RootState, RootActions, typeof extraThunkArgument>

Basically, the types of configureStore should match pretty closely the types of Redux's StoreCreator. A fully typed example of a call to createStore would look like this:

const store = createStore<
	RootState,
	RootActions,
	{
		dispatch: ThunkDispatch<
			RootState,
			typeof extraThunkArgument,
			RootActions
		>
	},
	{}
>(rootReducer, app.loadState())

Furthermore, there should be a good strategy for mocking this store, perhaps with a similar approach to @jedmao/redux-mock-store?

export default configureMockStore<
  RootState,
  RootActions,
  ThunkDispatch<RootState, typeof extraThunkArgument, RootActions>
>(middlewares)

This, however, would be a separate dev dependency and perhaps a separate GitHub issue as well.

@markerikson
Copy link
Collaborator

Hey, thanks for filing this.

I'm a bit hesitant to explicitly add an option for this directly to configureStore itself, for a couple reasons:

  • RSK aims to have the most common usages handled by default
  • If you need to customize the default middleware, you can override the middleware argument and pass in your own list. That would include a customized thunk instance
  • Conversely, it's also possible that people might have excluded the thunk middleware from the store setup, so that option might not apply.

Typings-wise, what happens if you do something like middleware: [thunk.withExtraArgument(someArg)] ? How does the resulting store type come out?

@markerikson
Copy link
Collaborator

Resolved by #192 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants