-
Notifications
You must be signed in to change notification settings - Fork 112
Add param/query transformation function to route definitions #214
Comments
Unless I've misunderstood the purpose of this, I think you might be better served with selectors than a transformation. That way the true state remains if you were to need it for something else. As we already have redux, and redux-little-router takes care of making sure that is up to date (#211 aside) with the query parameters, this is the minimum state. If you then want to get query parameters with a certain transformation, you could write (untested): import { createSelector } from 'reselect';
const getRouter = state => state.router;
export const getRouteQueryFeatures = createSelector(
[ getRouter ],
router => router.query && router.query.features ? router.query.features.split(',') : []
); Then in a component: import { getRouteQueryFeatures } from './selectors';
const FeatureList = props => <ul>{ props.features.map(feature => <li>{ feature }</li>) }</ul>;
export default connect(state => ({ features: getRouteQueryFeatures(state) }))(FeatureList); |
Yeah, i thought it just looked nicer to colocate the "type transformations" with the route, especially for params. I prefer the idea of storing |
I'm actually not sure why it is stored in redux at all when it could be calculated by a selector from the route. |
Yep, I agree with @dpwrussell that selectors are the tool for this job 😃 |
It would be sweet if there were transformation functions that could be applied to the parameters of the url or the query based on route
something like:
If this sounds good, and you would point me at some files i'd be glad to start a branch.
The text was updated successfully, but these errors were encountered: