redux-dynamic-modules icon indicating copy to clipboard operation
redux-dynamic-modules copied to clipboard

Initializing store

Open eddievagabond opened this issue 6 years ago • 4 comments

I am having issues initializing the store with the createStore provided via readux-dynamic-modules. I am most certainly doing something wrong, but could not figure out what. Any help would be appreciated.

const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
        ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
        // Options: http://zalmoxisus.github.io/redux-devtools-extension/API/Arguments.html
            actionCreators,
        })
        : compose;

    enhancers.push(applyMiddleware(...middleware));

    const enhancer = composeEnhancers(enhancers);
// With initial state
// ERROR: Uncaught (in promise) TypeError: Cannot read property 'concat' of undefined
const store = createStore(
                reducers(history),
                initialState,
                enhancer,
                [getSagaExtension({})],
            );
// Without initial state
// Error: It looks like you are passing several store enhancers to createStore(). This is not supported
const store = createStore(
                reducers(history),
               //  initialState,
                enhancer,
                [getSagaExtension({})],
            );

eddievagabond avatar Apr 01 '19 20:04 eddievagabond

It seems you are calling the createStore api incorrectly

You shouldn't pass reducers directly to createStore, but instead, create modules that you pass as the last arguments to the function.

See the todo-example in this repository for an example

abettadapur avatar Jun 20 '19 02:06 abettadapur

@abettadapur hey!

I guess @eddievagabond faced with the same problem that I did.

I also tried just import the createStore from redux-dynamic-modules and was thinking it will work without any changes.

And the reason why I did it, because I have A LOT of reducers (and sagas), and transform each of them to the modules can be a pain. And thinking of this huge refactoring make me crying D:

Is there a way to make it easy?

SmirnovW avatar Jun 24 '19 22:06 SmirnovW

You could create a single monolithic module that contains all your reducers and sagas and add that for now. Then you can refactor one by one as you go.

The whole purpose of the library is to modularize redux artifacts, so we only support module constructs

abettadapur avatar Jun 24 '19 22:06 abettadapur

If you could just replace the createstore function with our implementation, you wouldn't gain any of the benefits of the library :/

abettadapur avatar Jun 24 '19 22:06 abettadapur