Comments (6)
Hi,
This isolation is exactly what subspace is trying to achieve, where each reducer doesn't know anything about what's around it.
So looking at your small example there, and without seeing what's in the reducers reducers and components, I'm not sure you actually need subspace at all.
But assuming you have reasons to use it we have a whole docs page on accessing "global" state that might have a few tricks for you. I'd suggest starting with wormholes (we've found them the solution to most stste sharing problems)
https://ioof-holdings.github.io/redux-subspace/docs/advanced/GlobalState.html
If you need more help setting up and using your store in these advanced configurations, feel free to ask here :)
from redux-subspace.
Just based in the use of the namespaced
wrapper, It looks like you are using redux-subspace v1. Many of the global state solutions (like wormholes) only work from v2.
from redux-subspace.
Thanks a lot for proposing, I need help yes. I don't know if there is another solution.
My problem is that I've my "user" reducer that expose some function like the "update" user.
export const update = request => dispatch => {
const changeType = request.timezoneId ? 'timezone' : 'user';
dispatch({ type: UPDATE_PENDING });
return userService.update(request)
.then(user => storeUserOnClient(user))
.then(user => dispatch({ type: UPDATE_SUCCESS, user, changeType }))
.catch(error => dispatch({ type: UPDATE_ERROR, error, changeType }));
};
These methods are coming with some actions (on the same file):
case UPDATE_PENDING:
return {
...state,
isPending: true,
error: undefined,
changeType: action.changeType
};
break;
case UPDATE_SUCCESS:
const user = {
...state.user,
firstName: action.user.firstName,
lastName: action.user.lastName,
email: action.user.email
};
return {
...state,
user,
isPending: false,
error: undefined,
changeType: action.changeType
};
break;
case UPDATE_ERROR:
return {
...state,
isPending: false,
error: action.error,
changeType: action.changeType
};
break;
And this reducer is declared on the index of reducers dir with some other reducers, like this:
export default combineReducers({
router: routerReducer,
user,
signup,
whishlist,
setting
});
Component-side, I've two components that are using the reducer "user". The first one are using only the user reducers, like this:
const mapStateToProps = state => {
return {
user: state.user.user,
error: state.user.error,
isLoading: state.user.isPending,
changeType: state.user.changeType
};
};
const mapDispatchToProps = dispatch => bindActionCreators({ update }, dispatch);
export default connect(mapStateToProps, mapDispatchToProps)(MeProfilePage);
The second one is using the update function of the user reducer but also the setting reducers like that:
const mapStateToProps = state => {
return {
timezones: state.setting.timezones,
isLoading: state.setting.isPending,
user: state.user.user,
error: state.user.error
};
};
const mapDispatchToProps = dispatch => bindActionCreators({ fetchTimezones, update }, dispatch);
export default connect(mapStateToProps, mapDispatchToProps)(MeSettingPage);
The fetchTimezone
is working well and my dropdown is filled by the timezone issued from my API.
The update
function is also working and an http request is sent but when it returns to React, it automatically use the connected router to return to the first component that use update
function. Like if router had attached the use of the update
function to the first component.
The history.location value changes from "/me/settings" to "/me" (the me/ path is hosting the first component, and the "me/settings" the second one).
My two routes:
<Route path="/me" render={() => protect(MePage)} />
<Route path="/me/settings" render={() => protect(MePage)} />
I don't know if i'm clear in my explainations :(
If you need more details or if you have any idea... just tell me please.
Thanks
from redux-subspace.
Sorry for the delayed response @christophedebatz, I've been on parental leave and been struggling to find time for anything. I hope you haven't been struggling the whole time with this and found a solution or work around.
There's a lot going on in your explanation and I'm struggling to follow what the issue is and where it might be falling apart.
Are you able to set up a small codesandbox.io example that demonstrates it for us?
from redux-subspace.
Hi @mpeyper
Thanks for your reply. Don't worry about the delay!
So, I haven't found a real solution but I'm thinking on a work-around which is to create another rest endpoint to treat my http call and so to make another reducer and another action. Like this, the two pipes (the user update and the user-timezone update are separate).
I have not enough time for now to set up the problem on a js sandbox. When I'll have time, be sure you will be the first aware of!
Regards my friends.
from redux-subspace.
Closing due to inactivity. Happy to repoen if there is more discussion to be had.
from redux-subspace.
Related Issues (20)
- @types in redux-subspace-observable dependencies HOT 1
- TypeError: undefined is not an object (evaluating 'store.subspaceOptions') HOT 4
- [redux-subspace] Thunk actions not namespaced HOT 11
- Any ideas on subspacing components with render props? HOT 7
- Removing Subspaced Reducer HOT 3
- TypeError: Object doesn't support property or method 'startsWith' [redux-subspace] HOT 1
- react-redux-subspace support react-redux 7 HOT 2
- [redux-subspace]Being in a subspace, can I dispatch an action to an other one ? HOT 3
- Ability to provide specific enhancer to a subspace HOT 19
- [redux-subspace-saga] Support redux-saga@^1.0.0 HOT 5
- Error on parentSpace HOT 2
- Basic subspace example incorrect in docs HOT 1
- Compatibility issue with react-redux v6 HOT 3
- [redux-subspace] In namespaced reducer, actions should be global by default HOT 1
- Cannot view updated parent space state when using useParentSpace() [react-redux-subspace] [redux-thunk] HOT 11
- Subspaced Saga - React to global action HOT 4
- react-redux-subspace npm audit denial-of-service vulnerability in recompose/node-fetch HOT 1
- Action Required: Fix Renovate Configuration
- Deprecated
- Using a prefilled state with namespaced reducers causes loss of the default store values. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redux-subspace.