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

[mobx-starter] Example with optional isomorphism #148

Closed
nightwolfz opened this issue Mar 7, 2016 · 14 comments
Closed

[mobx-starter] Example with optional isomorphism #148

nightwolfz opened this issue Mar 7, 2016 · 14 comments

Comments

@nightwolfz
Copy link

I've just pushed an example with optional isomorphism and a nice way to structure your application.

All components get access to the state and all methods that affect the state (actions)
State is stored in one giant JSON object.
When state changes, components are re-rendered.

https://github.com/nightwolfz/mobx-starter

Inspired by one of the comments here asking for more examples, still a work in progress.

Enjoy !

This is a watered down version of what I'm using for https://instmsg.com/ (under development, over 100+ actions, 100+ components, sockets/MQTT...). Super maintainable so far :)

@mweststrate
Copy link
Member

Really cool! Gonna try to take a closer look later today

@nightwolfz
Copy link
Author

Documentation was written on the spot, eventually I will add some proper docs.
At the moment it's just an example of how useful mobx can be.

I will also add authentication / account management, sessions and a chat box (socket example) to it. That should cover most cases.

@mweststrate
Copy link
Member

@nightwolfz
Copy link
Author

I guess I can't back down anymore. Thanks Obama!

@mweststrate
Copy link
Member

:)

@rickmed
Copy link

rickmed commented Mar 8, 2016

@mweststrate don't let him back down! :)
@nightwolfz dude, that looks so awesome, I wish I could understand it a bit more (it's really over my head), specially the server side and the reasoning to give all components access to all actions.

@nightwolfz
Copy link
Author

@rickmed I have just added mongo support with user registration and auth.

I'm trying to emulate Flux/Redux's unidirectional flow in different way.

In the case of redux, you have actions, a dispatcher and reducers.

Here we just have actions, which are just namespaced functions (namespace = action filename) that affect the state.

All the re-rendering is taken care by mobx so you can only focus on two things:

What to name your action? and what should it do?

[Edit]

Sorry had to remove it guys cos it contained some "work related" code :(

Enjoy whoever got a shot at it !

@worifon
Copy link

worifon commented Mar 9, 2016

@nightwolfz
Oh no! please give me chance to get it. I will use it for learning purpose only.

@mweststrate
Copy link
Member

Closed the issue. It's not available anymore 😢

@bySabi
Copy link

bySabi commented Mar 10, 2016

RIP

someone already clone it?? ...
It have a proper license for reanimate it ?? ...
we need start a change.org request ?? ...

@nightwolfz
Copy link
Author

It's not that hard to re-create a simple version of it. The basis for it is in https://github.com/nightwolfz/ryan (the @connect decorator).

You will need your context to contain two things: your state and your store which is a collection of functions that I like to call actions. The store itself has no state.

You just have to figure out how to pass that context into your actions (yes, you need to pass actions to actions, it's a graph).
You'll probably want that context in your react-router routes as well for handling auth/roles.

If your components end up looking like this:

import React from 'react'
import { connect } from 'ryan'

@connect
class Home extends React.Component {

    render() {
        const { state, store } = this.context

        return <section>
            <h1>Home</h1>

            {state.user 
                ? <p>Welcome back, {state.user.username}</p>
                : <a onClick={() => store.user.login()}> Login </a>
            }
        </section>
    }
}

export default Home

You're are on the right path.

@bySabi
Copy link

bySabi commented Mar 10, 2016

Github has made us lazy! not body forked before 'The Grant Delete' :-(

Is a lost for "HumanityX"

We still have ryan. And Yes! I already forked it :-)

Let´s see if "slow brainers" like me can assemble 'MobX, 'React-router async', '...' puzzle.

The mobx-starter poster for for nostalgics.

UPDATE:
The mobx-starter Collector`s Edition 'poster'

@nightwolfz
Copy link
Author

@bySabi that README is awful :) I updated it a bit right before removing everything

https://gist.github.com/nightwolfz/aeaa0e144402e45b824c

@bySabi
Copy link

bySabi commented Mar 10, 2016

@nightwolfz I update 'poster' :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants
@nightwolfz @mweststrate @bySabi @rickmed @worifon and others