Giter Club home page Giter Club logo

Comments (6)

jpeyper avatar jpeyper commented on May 27, 2024

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.

mpeyper avatar mpeyper commented on May 27, 2024

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.

christophedebatz avatar christophedebatz commented on May 27, 2024

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.

mpeyper avatar mpeyper commented on May 27, 2024

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.

christophedebatz avatar christophedebatz commented on May 27, 2024

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.

mpeyper avatar mpeyper commented on May 27, 2024

Closing due to inactivity. Happy to repoen if there is more discussion to be had.

from redux-subspace.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.