ioof-holdings / redux-dynostore

These libraries provide tools for building dynamic Redux stores.
BSD 3-Clause "New" or "Revised" License
122 stars 15 forks source link

Thunk support #160

Closed lostincomputer closed 4 years ago

lostincomputer commented 4 years ago

Is Redux Thunk supported?

I configured my store to

import { createStore } from "redux"; import { rootReducer } from "./reducers"; import { composeWithDevTools } from "redux-devtools-extension"; import dynostore, { dynamicReducers } from "@redux-dynostore/core"; import thunk from "redux-thunk"; import { applyMiddleware } from "redux-subspace";

export const store = createStore( rootReducer, composeWithDevTools(dynostore(dynamicReducers()), applyMiddleware(thunk)) )

but my thunk doesn't get executed.

mpeyper commented 4 years ago

Yes, thunks are supported.

The store setup looks fine so I'll need to see the thunk and how you're dispatching it to help you out any further.

I'm on holidays at the moment, so my response times might be a bit slow.

lostincomputer commented 4 years ago

I tested it again and it works now for some reason. I spent an hour trying to fix it yesterday and thought that it had something to do with your library. Sorry for wasting your time.

mpeyper commented 4 years ago

Ha, no worries.

I have to mention one thing though:

export const Spreadsheet = props => {
  const ConnectedSpreadsheet = dynamic(
    props.identifier,
    subspaced(),
    attachReducer(spreadsheetReducer)
  )(UnconnectedSpreadsheet);

  return <ConnectedSpreadsheet {...props} />;
};

There is an issue with this snippet. dynamic creates a higher-order component, which you shouldn't do as part of rendering (i.e. you should call it inside the Spreadsheet function component). See this article on the react docs for more details.

For basic use cases, you can us the createInstance function to change the identifier for multiple instances, but you do need to know what they identifiers are going to be.

I've seen cases where useMemo to dynamically change the identifier and only recreate the component when the identifier changes, and we've had discussions before about accepting identifier as a prop instead of having to statically assign them, but nothing has ever come of it.