HenrikJoreteg / redux-bundler

Compose a Redux store out of smaller bundles of functionality.
https://reduxbundler.com
583 stars 46 forks source link

navigation and enhancers #21

Open quarkcore opened 6 years ago

quarkcore commented 6 years ago

@HenrikJoreteg hi, which kind of navigation u are unsing? i try to add react-router with react-router-redux but have some trouble.

ther for i need to add some middleware but applayMiddleware() of your package does not working as expected.

import createStore from '...';
import { applyMiddleware } from 'redux-bundler';

import { testEnhancer } from '...';

//used like that console.log in testEnhancer never logs
store = createStore({}, applyMiddleware(testEnhancer()));

any idea?

quarkcore commented 6 years ago

Works like that! strange behavoir anyhow. why cant i pass an empty object as initial state?

import createStore from '...';
import { applyMiddleware } from 'redux-bundler';

import { testEnhancer } from '...';

store = createStore(applyMiddleware(testEnhancer()));
HenrikJoreteg commented 6 years ago

@quarkcore you should read my book 😀 there's a whole chapter on routing. Anway... this is how I do routing:

URL bundle + Route bundle: https://github.com/HenrikJoreteg/redux-bundler-example/blob/master/src/bundles/routes.js

Then this one helper at the root of your component tree: https://github.com/HenrikJoreteg/redux-bundler-example/blob/master/src/components/layout.js#L17 this makes it so you don't need any special "link" tags or anything just render regular <a> tags and as the clicks bubble up this helper sorts out whether to treat it as internal navigation or not.

Then I use selectRoute to grab the current component based on the routes, and assign it to <Page/> and render it: https://github.com/HenrikJoreteg/redux-bundler-example/blob/master/src/components/layout.js#L13

Anywhere you need route params you can just use selectRouteParams to get an object of named route parameters or selectPathname to get current pathname, etc. The URL bundle has tons of selectors.

olizilla commented 6 years ago

We just hit the same issue. We have to do hash-based routing (our app may not be mounted at the root of the domain) and are trying to figure out how best to get it working with redux-bundler. We could sprinkle hash based routes all over the code, but we thought we'd try mixing it with react-router first to see if that could work. Neither approach seems ideal.

olizilla commented 6 years ago

We got hash based routing working the redux-bundler way by parameterising the routeInfo selector in create-route-bundle... https://github.com/HenrikJoreteg/redux-bundler/pull/23