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

reduxDevtools plugin for namespaced stores #88

Closed
erixtekila opened this issue Aug 19, 2019 · 8 comments
Closed

reduxDevtools plugin for namespaced stores #88

erixtekila opened this issue Aug 19, 2019 · 8 comments
Assignees
Labels

Comments

@erixtekila
Copy link

I wonder how it'd be possible to use the devtools with namespaced store.
An error is thrown.

export default createConnectedStoreAs
(
    {
        i18n
        , urls : manifest.urls
    }
    ,stores => withReduxDevtools( effects(stores) ) 
);

Is it feasible ?
Any other way to compose connected stores ?

@bcherny bcherny self-assigned this Aug 20, 2019
@bcherny
Copy link
Owner

bcherny commented Aug 20, 2019

Hey there @erixtekila! You want to do something like this:

export default createConnectedStoreAs(
  {i18n, urls: manifest.urls},
  ({i18n, urls}) => ({
    i18n: withReduxDevtools(withEffects(i18n)),
    urls: withReduxDevtools(withEffects(urls))
  })
);

I encourage you to use the useStore hook and createConnectedStore instead, which makes it more ergonomic to avoid createConnectedStoreAs.

@bcherny bcherny closed this as completed Aug 20, 2019
@erixtekila
Copy link
Author

Thanks.
The useStores hook seems also ergonomic to me.

Could you elaborate on why createConnectedStoreAs is not, please ?

@erixtekila
Copy link
Author

erixtekila commented Aug 20, 2019

And also, why withEffect is not documented anywhere ?
Is it a deprecated HOC or something ?

What this function do, that effect() don't ?
Could I write it like so :

export default createConnectedStoreAs
(
    {
        i18n
        , urls : manifest.urls
    }
    ,{ i18n, urls } => 
    (
         {
           i18n : withReduxDevtools(withEffects(i18n)
          , urls: withReduxDevtools(withEffects(urls))
         }
      )
); 

Namespaced stores are convenient to make there properties reactive.
Flat stores don't expose nested fields, ain't it ?
Something along the line :

store.get( "i18n.yes" )

where yes is a sub field of i18n.

@bcherny
Copy link
Owner

bcherny commented Aug 24, 2019

Could you elaborate on why createConnectedStoreAs is not, please?

useStore is a way to keep your stores decoupled. With the hooks API, there's no need for createConnectedStoreAs anymore (the reason I introduced it originally was to reduce the boilerplate it takes to hook up a component to multiple stores using the withStore HOC API). useStores is simpler, and might make it easier for others to understand your code.

@bcherny
Copy link
Owner

bcherny commented Aug 24, 2019

And also, why withEffect is not documented anywhere

withEffect/effect is a function that you define, so you can call it anything :) See https://undux.org/#quick-start/2.

store.get( "i18n.yes" )

That API wouldn't be typesafe, unfortunately.

@erixtekila
Copy link
Author

erixtekila commented Aug 25, 2019

Thanks @bcherny
At first, I thought useStores (ending "s") was related to createConnectedStoreAs (ending "as").
It seems that it is not the case.
I'll dig in the source to understand and maybe document my findings.

Your tests seems a good learning path too !

@bcherny
Copy link
Owner

bcherny commented Aug 25, 2019

So to clarify:

  • useStore is the name of the React hook that's created when you call createConnectedStore
  • useStores is the name of the React hook that's created when you call createConnectedStoreAs

Hope that makes sense :)

@erixtekila
Copy link
Author

Ah, you confirm what I've found.
Thanks

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

No branches or pull requests

2 participants