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

getGlobal #35

Closed
lishine opened this issue Jan 11, 2019 · 12 comments
Closed

getGlobal #35

lishine opened this issue Jan 11, 2019 · 12 comments
Assignees
Labels
feature A new feature is requested.
Milestone

Comments

@lishine
Copy link

lishine commented Jan 11, 2019

No description provided.

@quisido
Copy link
Collaborator

quisido commented Jan 11, 2019

It isn't currently publicly accessible, or if it is it's not by design. It follows the law of encapsulation. All exposed states are copies of the state such that direct access to mutate isn't possible.

What is your use case for copying state outside of React, and maybe it can be worked around, or maybe it will be convincing to publicly expose the global state?

@lishine
Copy link
Author

lishine commented Jan 11, 2019

I just mean to use it like store.setState({count:1}) outside of react component. Like with easy-peasy

@justinhandley
Copy link

justinhandley commented Jan 11, 2019 via email

@quisido
Copy link
Collaborator

quisido commented Jan 11, 2019

Setting the state can, yes. It's not recommended over this.setGlobal or the useGlobal hook, but there are no current side effect of doing so. It may not work in the future for server side rendering, since each component will have its own store context, but for the default ReactN use case with a single store, there is no problem.

import { setGlobal } from 'reactn';

Let me know if you have any further questions or if this issue can sufficiently be closed.

@umbertoghio
Copy link
Contributor

umbertoghio commented Jan 28, 2019

Hi,
I am trying out ReactN on a new project, so far so good :-)

As I am working on a library function it will be glad to access the store directly (now I am passing this.global from reactn components).

I am now trying to import setGlobal directly, but it will be great to have a way to access "this.global" outside of a reactn component... as workaround I also found that I can make a class that extends react(n).component but I like more regular functions

Thanks!

*Edit: I'm using react 16.5.0 so no useGlobal hooks :-(

@quisido
Copy link
Collaborator

quisido commented Jan 28, 2019

Not currently, but I'm not opposed. Would something like getGlobal() be what you're looking for? A current snapshot of the global state?

@umbertoghio
Copy link
Contributor

that would be great!

I switched one project to Reactn and it’s incredible how easy it is to manage global state....

setGlobal() works perfectly inside library functions, while creating a class component
without render (just to access state) is not an option as it get hit with a force update when setting global state.

Thank you very much for your great work!

@quisido
Copy link
Collaborator

quisido commented Jan 29, 2019

I'll try to have an iteration of this soon for single-store support only.

@quisido quisido added this to the 0.2.0 milestone Jan 29, 2019
@quisido quisido self-assigned this Jan 29, 2019
@quisido quisido changed the title Can the store be used outside react components? getGlobal Jan 29, 2019
@quisido quisido added the feature A new feature is requested. label Jan 29, 2019
@quisido
Copy link
Collaborator

quisido commented Feb 1, 2019

I'd just like to state that I have this existing in my local repository, but it's pretty important to me that I get unit tests completed for the project as a whole before cutting a new version, so I do not have an ETA on release. I may do an alpha release if the unit tests delay this too much.

@quisido quisido assigned quisido and unassigned quisido Feb 1, 2019
@umbertoghio
Copy link
Contributor

I am currently migrating a medium size (25 screens) Expo React Native project from Unstated to Reactn, if you release the alpha version with GetGlobal I can help with testing it out :-)
Thank you for your work!

@quisido quisido closed this as completed in 7c6f293 Feb 2, 2019
@quisido
Copy link
Collaborator

quisido commented Feb 4, 2019

I have released [email protected] to include this functionality as getGlobal. The documentation for getGlobal has been added to the README.

I added some unit tests and manual app testing to try to insure there were no breaking changes, but this version included a major change to some internal workings. I would love some community feedback on if any errors are discovered.

Thank you for your patience. I'm sorry about the long delay. I have been unable to contribute for the past month, but I'm hoping to begin knocking out a lot of ReactN's open issues now.

@umbertoghio
Copy link
Contributor

Thank you for the quick release!
I am almost done migrating my app to Reactn and so far it is working flawlessly, including the getGlobal

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

4 participants