Skip to content

Pass options to devtools #65

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

Closed
anilanar opened this issue Mar 5, 2019 · 12 comments · Fixed by #97
Closed

Pass options to devtools #65

anilanar opened this issue Mar 5, 2019 · 12 comments · Fixed by #97

Comments

@anilanar
Copy link
Contributor

anilanar commented Mar 5, 2019

Although it is convenient to include devtools integration in this library, there's a fair question to ask here: is it this library's responsibility to do it? If it's done for technical reasons, I think we need a way to pass options to the devtools' compose function.

Particularly action blacklisting, state sanitization, max-age are invaluable for large apps.

In addition, different apps have different needs (e.g. using devtools in production etc.). There are infinitely many possible ways to configure devtools. What if createStore took a compose function as a parameter?

Another alternative (as seen in other issues/questions submitted) is to have an additional API that exports enhancers/middlewares for dynamic module management and let users seeking more freedom use createStore from redux.

If you would like to go with the first option (adding compose param to createStore), I can make a PR. I suggest that createStore’s first argument is made an options object in that case e.g. createStore<...>(options: { compose, initialState, enchancersEtc }, ...modules). I’m typing from mobile so this is not a type signature 😄

It seems it’d be better if this were done after #55 is merged. Nevertheless this will be a breaking change.

@anilanar
Copy link
Contributor Author

anilanar commented Mar 7, 2019

For now, I have a fork that makes createStore take compose function as an argument.

@navneet-g
Copy link
Contributor

@anilanar Please feel free to send a PR.

@navneet-g
Copy link
Contributor

@anilanar what if we create an option to createStore that tells it to not compose with devtools, and you can pass devtools as an enhancer in createStore?

@anilanar
Copy link
Contributor Author

anilanar commented Mar 28, 2019

@navneet-g Devtools' compose function iterates all enhancers and generates an instanceId for each intermediate store created by enhancers and stores them somewhere:

https://github.com/zalmoxisus/redux-devtools-extension/blob/master/src/browser/extension/inject/pageScript.js#L383-L400

I don't understand why it needs to do that though. So createStore({}, [reduxDevtoolsCompose(/* enhancers */)]) would make devtools miss enhancers added by redux-dynamic-modules' own createStore.

@dbartholomae
Copy link

Any way I can help here? This is a major hindrance for us using this package now :-/

@anilanar
Copy link
Contributor Author

anilanar commented Apr 14, 2019

I don’t see a way to make this a non-breaking change.

If maintainers are fine with a breaking change, and if they propose the new API, I can make a PR. Otherwise I don’t want to waste time on bikeshedding and on a PR.

@navneet-g
Copy link
Contributor

@abettadapur what if we take a compose function as input? @dbartholomae @anilanar will that help?

@dbartholomae
Copy link

Taking a function sounds great! And if enhancers is a function instead of a middleware, dev-tools are not included by default. If this approach is fine, I could try to write a PR.

@anilanar
Copy link
Contributor Author

anilanar commented Apr 14, 2019

I propose:

// The following plus 8 overloads for `DeepPartial<union of module states>`

interface StoreOptions<S> {
  initialState: S,
  enhancers?: StoreEnhancer[],
  extensions?: IExtension[],
  compose?: typeof reduxCompose,
  modules: IModule<any>[],
}

export declare function createStore<S>(options: StoreOptions<S>): IModuleStore<S>;

It might be possible to avoid overloads with some Typescript 3.0+ type-level wizardry: microsoft/TypeScript#26058 (comment)

If someone's into it, it may be possible to take a tuple of modules like <M extends IModule<any>[]> and convert it to tuple of states with { [K in keyof M]: M[K] extends IModule<infer S> ? S : never } and then convert the tuple of states to intersection of states using the method provided in the link. Finally using initialState: DeepPartial<CalculatedState> and overloads are gone.

@anilanar
Copy link
Contributor Author

I'm working on this now.

@dbartholomae
Copy link

Any news on the PR? Looking forward to this!

@anilanar
Copy link
Contributor Author

anilanar commented Aug 23, 2019 via email

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.

3 participants