question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Create a "combineStores" utility function to combine stores

See original GitHub issue

Feature Description

Currently, we create “combined” stores like this: https://github.com/google/site-kit-wp/blob/507e81f4af2b52e77db6a71710777d5ea086302b/assets/js/googlesitekit/modules/create-module-store.js#L59

But that’s a bit verbose and makes combining multiple stores together a bit annoying. We should create a utility that combines stores—even ones that lack certain keys.


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • Create a combineStores( …args ) function that accepts a list of stores and combines their actions, reducers, etc. for multiple stores and returns a single store. It should not require that stores have all store properties (eg. initialState, actions, etc.) and should use sane defaults for any missing values.
  • It should still fail if duplicate keys are found, similar to the collectActions, etc. functions.

Implementation Brief

  • Add a combineStores( …args ) function that accepts full stores as arguments, each with the object shape:
{
  INITIAL_STATE,
  actions,
  controls,
  reducer,
  resolvers,
  selectors,
}

Note that every value should be optional, because it’s possible to have a store that doesn’t have controls, or even selectors, etc. We can provide sane defaults for other things like reducer or initialState if none are provided. (Though equally, I’d be fine if initialState was also required.)

const store = Data.combineStores(
	{
		actions: Data.commonActions,
		controls: Data.commonControls,
	},
	connection,
	info,
	reset,
	notifications,
);

Data.registerStore( STORE_NAME, store );

QA Brief

Changelog entry

  • Add googlesitekit.data.combineStores utility function to combine multiple datastore objects.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
felixarntzcommented, Apr 22, 2020

IB ✅

Let’s have all parts of the object optional including INITIAL_STATE and use defaults (INITIAL_STATE could just be an empty object).

0reactions
felixarntzcommented, May 6, 2020

@jqlee85 Yeah exactly, sorry for being a bit unprecise in my comment above. combineStores should not use any initialization logic indirectly either 👍 The actual problem as mentioned lies in addInitializeAction being called with an empty object for commonStore.

Read more comments on GitHub >

github_iconTop Results From Across the Web

combineReducers(reducers) - Redux
This function helps you organize your reducers to manage their own slices of state, similar to how you would have different Flux Stores...
Read more >
combineStore, React native create store, createStore ...
It turns out that Redux lets us combine multiple reducers into one that can be passed into createStore by using a helper function...
Read more >
tapayne88/combine-selectors-redux - GitHub
Utility function for combining selectors when working with redux. Much like combineReducers it helps for defining selector functions within the reducers.
Read more >
anew - npm
The createStore utility allows you to create a Redux store without the ... The combineStores utility is very similar to the combineReducer ......
Read more >
Utility function that uses the store - Stack Overflow
I am working with react and I need to create a utility function that uses a parameter from the redux store.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found