Skip to content

Conversation

@Moocar
Copy link
Contributor

@Moocar Moocar commented Apr 1, 2019

Description

As part of my work on #13004, I've been trying to remove reliance on global events such as BOOTSTRAP_FINISHED. There are definitely some good use cases for global events, but I feel in this case, the code is more clear by specifically invoking db.saveState/autoSave. Curious on other's thoughts.

Related Issues

@Moocar Moocar requested a review from a team April 1, 2019 23:54
@Moocar Moocar changed the title [gatsby/db]: expicitly call db saveState and autoSave refactor(gatsby): expicitly call db saveState and autoSave Apr 1, 2019
@Moocar Moocar force-pushed the db-explicitly-autosave branch from ef59859 to 41db68a Compare April 2, 2019 05:14
Copy link
Contributor

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This is more readable!

Just wondering why we're listening on emitter and not on the redux state changing itself (perhaps redux state change is happening to often?)

I'm holding off on merges as I want @pieh to have a look as well.

@Moocar
Copy link
Contributor Author

Moocar commented Apr 2, 2019

Just wondering why we're listening on emitter and not on the redux state changing itself

Do you mean by registering a reducer that reacts to any redux action? My guess is that we would have no guarantee that all other reducers had executed before performing the save. Whereas emitter is emitted via a subscription to redux, which is guaranteed to fire after all reducers have finished.

@pieh
Copy link
Contributor

pieh commented Apr 2, 2019

I think we need to remove startAutosave call from bootstrap with this?

require(`../db`).startAutosave()

@Moocar Moocar requested a review from a team April 2, 2019 21:07
@Moocar
Copy link
Contributor Author

Moocar commented Apr 2, 2019

I think we need to remove startAutosave call from bootstrap with this?

Good catch. Fixed in 5028776

@Moocar Moocar force-pushed the db-explicitly-autosave branch from f6a254e to ab14d84 Compare April 3, 2019 21:07
@Moocar
Copy link
Contributor Author

Moocar commented Apr 3, 2019

@pieh conflicts resolved

@wardpeet wardpeet merged commit 31f1c72 into gatsbyjs:master Apr 4, 2019
@Moocar Moocar deleted the db-explicitly-autosave branch April 4, 2019 22:25
@sidharthachatterjee
Copy link
Contributor

Published in gatsby@2.3.14

johno pushed a commit to jlengstorf/gatsby that referenced this pull request Apr 10, 2019
…13007)

* [gatsby/db]: expicitly call db saveState and autoSave

* don't db.startAutosave() during bootstrap

* saveState at beginning of db.startAutosave()
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 this pull request may close these issues.

4 participants