Refactor StateStore
to remove dependency on the atom
global
#1256
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I had occasion to visit
src/state-store.js
and thought I'd refactor it a bit.I know we have this annoying problem where we want to rely on the
atom
global, but we end up acting before it's defined. This is vexing toStateStore
, since it wants to read from config to decide which kind of adapter to use (IndexedDB or SQL). In this case, we can pass theconfig
instance into the constructor, dependency-injection–style. By the time we actually need to read the config, it's been initialized and is ready to read values.The SQL adapter also needs to know where to store its DB, so it reads
atom.getConfigDirPath()
. This value can't be introspected fromatom.config
, and it isn't even ready by the time we createStateStore
; it gets initialized later in the environment setup process. The fix is similar to the fix for a lot of similar objects created during bootstrapping: a second “initialization” phase where the later properties can get set. This is still early enough to be set before the first time we need to actually useStateStore
, so it all works out.This allows us to simplify the implementation of
src/state-store.js
and make some more methods synchronous. (They still go async later, but the code is easier to read this way.) We also no longer need to do the awkward thing where we check for theatom
global every 50ms.All the relevant tests seem to pass locally, but let's see what CI says.