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

[1.0] Use Redux for managing Gatsby's internal server state #777

Closed
KyleAMathews opened this issue Apr 4, 2017 · 11 comments
Closed

[1.0] Use Redux for managing Gatsby's internal server state #777

KyleAMathews opened this issue Apr 4, 2017 · 11 comments

Comments

@KyleAMathews
Copy link
Contributor

KyleAMathews commented Apr 4, 2017

I've been prototyping using Redux for managing Gatsby's internal server/cli state to replace the somewhat ad-hoc data management code.

I needed to refactor this code anyways to get data hot reloading working (#1 requested feature for people experimenting with Gatsby v1) and figured I'd try this out.

I'm about 1/2 way through ripping out the old code and replacing it with Redux but I've very positive about the direction. The data flows are much simpler, much more testable, and it's suggesting very positive changes to a few Gatsby APIs.

And the nice thing about Redux is since the community is huge, like with GraphQL, we'll get freebies by adopting Redux.

E.g. built-in devtools support.

This screenshot is the Redux devtools looking at an action from my Gatsby blog where I opened a markdown file, made a small change, and saved it and this is the resulting state diff.

screen shot 2017-04-03 at 11 56 48 pm

In addition to the nice code improvements plus our now built-in supercharged debugger, using Redux will make Gatsby's code base feel very approachable to many of its users who will have experience using Redux on client-side apps.

@KyleAMathews KyleAMathews changed the title Use Redux for managing Gatsby's internal state Use Redux for managing Gatsby's internal server state Apr 4, 2017
@jthiesse
Copy link

jthiesse commented Apr 4, 2017

Would the GraphQL plugins populate the store and the components receive data via react-redux or would GraphQL data continue to be part of each component?

@KyleAMathews
Copy link
Contributor Author

@jthiesse redux is only being used on the server piece not in the browser. It'll be invisible to users unless you're working on core code or some types of plugins.

@RohovDmytro
Copy link

Check redux-query lib — it's so awesome.

https://github.com/amplitude/redux-query

@KyleAMathews KyleAMathews changed the title Use Redux for managing Gatsby's internal server state [1.0] Use Redux for managing Gatsby's internal server state Apr 11, 2017
@KyleAMathews
Copy link
Contributor Author

PR is up! Would love some reviews from people more familiar with Redux #788

@danielo515
Copy link

Why don't you want to include redux as part of the generated app? There are situations where it makes a lot of sense

@KyleAMathews
Copy link
Contributor Author

@danielo515 you're free to add Redux if it's needed for your site... why would we want to always include it?

@danielo515
Copy link

Dear @KyleAMathews,

I'm not talking about including it always. I'm talking about providing an easy way to include it ( like activation) . For example , Nuxt does not include Vuex by default, but if you create an index.js file at the store directory then Vuex is included automatically, and injected to the components .
Does that make sense .

@KyleAMathews
Copy link
Contributor Author

Ah gotcha! Yeah, that would be cool. This would be perfect for a Gatsby v1 plugin https://www.gatsbyjs.org/docs/plugins/

@danielo515
Copy link

Nice to hear that ! Are you going to open an specific issue for that ? I would like to subscribe to it

@KyleAMathews
Copy link
Contributor Author

KyleAMathews commented Apr 11, 2017 via email

KyleAMathews added a commit that referenced this issue Apr 11, 2017
…fixes #777 (#788)

* Use DataTree instead of Abstract Syntax Tree

The idea for how to do things was taken from compilers
but since we're not actually parsing syntax into a tree, using
AST terminology is confusing. DataTree seems like a more sensible name.

* Add a watch command for all packages and update contributing instructions

* Add trailing slash when creating script tags for prefixed sites

* Add redux, convert all globals except pages to use it

* Add more tests + convert node api signature to (args, pluginOptions) to make same as browser/ssr api signature

* Use Redux for managing data nodes + initial rough implemenation of hot reloading

* Move raw action dispatching to action creator

* Add nodes tests

* Update windows docs

* Update CONTRIBUTING.md

* Somewhat reliable draining

* Upgrade gatsbygram for PR

* Up sites to latest canary
@KyleAMathews
Copy link
Contributor Author

This is now merged

mwfrost pushed a commit to mwfrost/gatsby that referenced this issue Apr 20, 2023
…fixes gatsbyjs#777 (gatsbyjs#788)

* Use DataTree instead of Abstract Syntax Tree

The idea for how to do things was taken from compilers
but since we're not actually parsing syntax into a tree, using
AST terminology is confusing. DataTree seems like a more sensible name.

* Add a watch command for all packages and update contributing instructions

* Add trailing slash when creating script tags for prefixed sites

* Add redux, convert all globals except pages to use it

* Add more tests + convert node api signature to (args, pluginOptions) to make same as browser/ssr api signature

* Use Redux for managing data nodes + initial rough implemenation of hot reloading

* Move raw action dispatching to action creator

* Add nodes tests

* Update windows docs

* Update CONTRIBUTING.md

* Somewhat reliable draining

* Upgrade gatsbygram for PR

* Up sites to latest canary
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

No branches or pull requests

4 participants