Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

Global Providers should have hooks as static methods (Provider.useGlobal) #37

Closed
ralphievolt opened this issue Jan 14, 2019 · 4 comments
Assignees
Labels
feature A new feature is requested.
Milestone

Comments

@ralphievolt
Copy link

ralphievolt commented Jan 14, 2019

Current is
setGlobal({ cards: [], disabled: false, initial: 'values', x: 1 });

Is it possible to group these global state like the following for better control and code management?

setGlobal-A({ cards: [], disabled: false, initial: 'values', x: 1 });

and

setGlobal-B({ posts: [], blogger: 5 });

@quisido
Copy link
Collaborator

quisido commented Jan 25, 2019

I'm not sure I understand what the difference between A and B are. Can you elaborate?

Are you looking to manage multiple global states?

@ralphievolt
Copy link
Author

yes.. and i want to group them according to their usage

@quisido
Copy link
Collaborator

quisido commented Feb 1, 2019

This won't be added, but there is a planned feature for multiple store contexts.

For example,

<Provider1><Cards /></Provider1>
<Provider2><Cards /></Provider2>

In the above Cards component, this.global.cards will have two separate values, as the values will be tied to the parent Provider.

This may suit your use case. However, there are no plans to have a single instance of <Cards /> have access to both Provider1 and Provider2's respective global states. You may prefer this.global.one.cards and this.global.two.cards instead.

The hooks implementation may support something like const [ value, setValue ] = Provider1.useGlobal('cards') to let you determine which provider to use, but that's a huge may and low priority. Let me know if it is something you would be interested in.

@quisido quisido added the feature A new feature is requested. label Feb 1, 2019
@quisido quisido changed the title Global State grouping Manage multiple global state instances with a single component. Feb 1, 2019
@bhgsbatista
Copy link

Provider1.useGlobal('cards') seems like a hook friendly version of React context. It seems much more natural to me.

@quisido quisido changed the title Manage multiple global state instances with a single component. Global Providers should have hooks as static methods (Provider.useGlobal) Feb 15, 2019
@quisido quisido self-assigned this Feb 15, 2019
@quisido quisido added this to the 1.0.0 milestone Feb 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature A new feature is requested.
Projects
None yet
Development

No branches or pull requests

3 participants