Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using MobX instead of Redux #187

Closed
perrosnk opened this issue Aug 8, 2016 · 36 comments
Closed

Using MobX instead of Redux #187

perrosnk opened this issue Aug 8, 2016 · 36 comments

Comments

@perrosnk
Copy link

perrosnk commented Aug 8, 2016

Is anyone using Mobx instead of Redux? If yes, would it be possible to share some boilerplate?

@mastermoo
Copy link

+1

1 similar comment
@miladebadi
Copy link

+1

@adamski
Copy link
Contributor

adamski commented Aug 10, 2016

Just started looking at MobX and I'd be interested in using it with RNN too..
+1

@adamski
Copy link
Contributor

adamski commented Aug 11, 2016

According to https://github.com/aksonov/react-native-mobx it is "framework free" so in theory should be able to use it with RNN as-is. I will try this soon...

@perrosnk
Copy link
Author

If you could share a boilerplate if you manage to do it, it would be very helpful for the whole community I think!

@mastermoo
Copy link

@perrosnk @adamski @knot123 there u go... navigation-mobx-example.
It's based on this redux-example.

@mastermoo
Copy link

@guyca it would make sense, to add the mobX example to this repo, as well. What do u think?

@guyca
Copy link
Collaborator

guyca commented Aug 13, 2016

@mastermoo Thanks for taking the initiative and making an example project. MobX sounds interesting and we're excited to hear you got navigation working with it. Are you using MobX with Navigation in production?

If it's ok with you, I'll link your project and this thread in the readme file. Adding another example project isn't feasable at this time, since we can't commit to another framework. We have a lot planned for the library and officially supporting another framework will add a lot of overhead.

@mastermoo
Copy link

Yes it's good with me.MobX is really a joy to use compared to redux. Yes, currently, I'm building a fairly complex app using Navigation and MobX. 😊Good to hear, that there is a lot planned for this library! I would really like to contribute to this repo, but I don't know any Objective C :/

    _____________________________

From: Guy Carmeli [email protected]
Sent: Sunday, August 14, 2016 12:47 AM
Subject: Re: [wix/react-native-navigation] Is it possible to use MobX instead of Redux? QUESTION
To: wix/react-native-navigation [email protected]
Cc: Yousef Kamawall [email protected], Mention [email protected]

@mastermoo Thanks for taking the initiative and making an example project. MobX sounds interesting and we're excited to hear you got navigation working with it. Are you using MobX with Navigation in production?

If it's ok with you, I'll link your project and this thread in the readme file. Adding another example project isn't feasable at this time, since we can't commit to another framework. We have a lot planned for the library and adding officially supporting another framework will add a lot of overhead.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

@guyca guyca changed the title Is it possible to use MobX instead of Redux? [QUESTION] Using MobX instead of Redux Aug 15, 2016
@stief510
Copy link

+1

2 similar comments
@vonovak
Copy link

vonovak commented Aug 15, 2016

+1

@maxs15
Copy link

maxs15 commented Aug 17, 2016

+1

@DanielZlotin
Copy link
Contributor

Great work @mastermoo !
One of the changes I have planned is to separate redux/mobx/other state containers from the core of this framework.

Optimally we would have the core Navigation, and on top of it (either another npm module completely or just a different module inside the framework) some wrappers that inject the state container logic into the screens.

For example you import react-native-navigation/redux or react-native-navigation/mobx instead of react-native-navigation.

This is just an idea right now as we have far more pressing concerns. In any case, this shouldn't be hard, and far more extensible. Can be assigned to milestone 2.1.0 I think.

@DanielZlotin DanielZlotin added this to the 2.1.0 milestone Aug 18, 2016
@DanielZlotin DanielZlotin self-assigned this Aug 18, 2016
@grin
Copy link
Contributor

grin commented Sep 24, 2016

@DanielZlotin though, do we even need to make RNN aware of any framework (Redux/MobX) at all?
IMHO that shouldn't be necessary (even with separate npm modules).
Instead of _registerComponentRedux and _registerComponentNoRedux functions we could have just one function similar to this:

function _registerComponent(screenID, generator, CustomWrapper) {
  const generatorWrapper = function() {
    const InternalComponent = generator();
    return class extends Screen {
      // ...
      render() {
        if (CustomWrapper) {
          return (
            <CustomWrapper>
              <InternalComponent navigator={this.navigator} {...this.state.internalProps} />
            </CustomWrapper>
          );          
        } else {
          return (
            <InternalComponent navigator={this.navigator} {...this.state.internalProps} />
          );          
        }
      }
    };
  };
  registerScreen(screenID, generatorWrapper);
  return generatorWrapper;
}

which just takes a user-provided wrapper component.
So for example, to enable Redux in your app all you'd need to do would be to add this to the app:

function CustomReduxWrapper(props) {
  return (
    <Provider store={store}>
      {props.children}
    </Provider>
  );
}

and then register a screen with this:

Navigation.registerComponent('app.ExampleScreen', () => Example, CustomReduxWrapper);

The benefit of this approach is that it removes knowledge of Redux (Provider + store) from RNN and also enables support for other frameworks.

As for MobX support, my understanding is that it's already possible by just decorating components with @observer, so no need of any work on RNN side other than maybe adding some more docs/examples.

@DanielZlotin
Copy link
Contributor

Completly agree, and that was my plan. However I do think a helper wrapper
function can be useful for some.

On Sep 24, 2016 3:45 PM, "grin" [email protected] wrote:

@DanielZlotin https://github.com/DanielZlotin though, do we even need
to make RNN aware of any framework (redux/mobx) at all?
IMHO that shouldn't be necessary (even with separate npm modules).
Instead of _registerComponentRedux and _registerComponentNoRedux
functions we could have just one function similar to this:

function _registerComponent(screenID, generator, CustomWrapper) {
const generatorWrapper = function() {
const InternalComponent = generator();
return class extends Screen {
// ...
render() {
if (CustomWrapper) {
return (

<InternalComponent navigator={this.navigator} {...this.state.internalProps} />

);
} else {
return (
<InternalComponent navigator={this.navigator} {...this.state.internalProps} />
);
}
}
};
};
registerScreen(screenID, generatorWrapper);
return generatorWrapper;
}

which just takes a user-provide wrapper component.
So for example, to enable Redux in your app all you'd need to do would be:

function CustomReduxWrapper(props) {
return (

{props.children}

);
}

and then register a screen with this:

Navigation.registerComponent('app.ExampleScreen', () => Example, CustomReduxWrapper);

The benefit of this approach is that it removes knowledge of Redux
(Provider + store) from RNN and also enables support for other frameworks.

As for MobX support, my understanding is that it's already possible by
just decorating components with @observer, so no need of any work on RNN
side other than maybe adding some more docs/examples.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#187 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AGWgj7cHGuHox8zbVlWT9Fl8hbZT0gXFks5qtRt6gaJpZM4Je8Sr
.

@danikenan
Copy link

+1

2 similar comments
@holmesal
Copy link

holmesal commented Oct 5, 2016

+1

@pietgk
Copy link

pietgk commented Dec 3, 2016

+1

@megahertz
Copy link
Contributor

I've created the mobx-react Provider which can be used with RNN.
https://gist.github.com/megahertz/3aad3adafa0f7d212b81f5e371863637

@bawn
Copy link

bawn commented Feb 13, 2017

+1

@DanielZlotin DanielZlotin removed this from the 2.1.0 milestone Feb 19, 2017
@kyle-ssg
Copy link
Contributor

I share @grin 's opinion on this - I think any form of coupling with things outside of react would hinder the project a great deal

@keyadesai
Copy link

+1

2 similar comments
@justinhaaheim
Copy link

+1

@didil
Copy link

didil commented Apr 24, 2017

+1

@kanzitelli
Copy link
Contributor

kanzitelli commented Apr 30, 2017

Hey guys,

I have created a small boilerplate RNN + MobX with Provider (so we can use @inject('store_name')) as @megahertz described before

https://github.com/kanzitelli/react-native-navigation-mobx-boilerplate

And if anyone is going to try it, please let me know how it goes 👍

@anhtuank7c
Copy link
Contributor

@kanzitelli
Thank you so much.
You saved my day.

@avishayil
Copy link

Hey @kanzitelli , I noticed that componentWillReceiveProps does not work on observer components, like FirstTab.
Any idea why?

@yezongyang
Copy link

use componentWillReact

@drewmca
Copy link

drewmca commented Jul 17, 2017

+1

5 similar comments
@andreaskarantzas
Copy link

+1

@ethanyanjiali
Copy link
Contributor

+1

@colincwilliams
Copy link

+1

@romandubrov
Copy link

+1

@LouisJS
Copy link

LouisJS commented Feb 6, 2018

+1

@kyle-ssg
Copy link
Contributor

kyle-ssg commented Feb 6, 2018

You guys should close this issue, state management has nothing to do with this project surely.

@JorgeCeja
Copy link

+1

@guyca guyca closed this as completed Apr 23, 2018
@wix wix locked and limited conversation to collaborators Apr 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests