Coder Social home page Coder Social logo

gantman / reactstatemuseum Goto Github PK

View Code? Open in Web Editor NEW
1.6K 24.0 92.0 7.35 MB

A whirlwind tour of React state management systems by example

License: MIT License

JavaScript 39.89% Java 12.37% Objective-C 21.38% HTML 15.29% CSS 0.02% Starlark 10.32% Ruby 0.74%
react react-native redux mobx mobx-state-tree apollographql appsync react-automata unstated freactal

reactstatemuseum's Introduction


One Packing List App Written in:

Technology React React Native
setState
React 16.x Context
React 16.x useContext
Redux
MobX
unstated
MobX-State-Tree
GraphQL Apollo + Amazon AppSync
apollo-link-state
setState + react-automata
Freactal
pure-store
ReactObservableStore
react-easy-state
rematch
unistore
Microstates
react-recontext
remx Coming Soon - Contribute Here?
simple-remx
constate
controllerim Coming Soon - Contribute Here?
immer
parket Coming Soon - Contribute Here?
react-contextual Coming Soon - Contribute Here?
react-copy-write Coming Soon - Contribute Here?
react-simplified
reim Coming Soon - Contribute Here?
React 16.x Context + Redux Coming Soon - Contribute Here?
ReComponent Coming Soon - Contribute Here?
undux Coming Soon - Contribute Here?
React 16.7.0-alpha useState Hook
redux-lightweight Coming Soon - Contribute Here?
overmind Coming Soon - Contribute Here?
Venti Coming Soon - Contribute Here?
Recoil Coming Soon - Contribute Here?
Effector Coming Soon - Contribute Here?
zustand Coming Soon - Contribute Here?
Jōtai Coming Soon - Contribute Here?

Examples to help portray the how, why, which, pros, and cons of various state management systems in the React ecosystem.

Every app is meant to be small, simple, and the same as each other. The only difference should be the state management decisions of each. The repeated React and ReactNative app is a Packing List, with the name based on the state technology.

Web Native
example gif of app example gif of app

What are the differences?

Ye honest truth here

This repo exists so you can look at the code for yourself, OR check this blog post on my findings if you'd like:

To Run Web

  • Click the codesandbox link in the list above
  • OR Clone this repo, then cd into each folder and follow the directions in readme

To Run Native

  • Clone this repo, then cd into each folder and follow the directions in readme

Contributors

Special thanks to all the wonderful people who contributed in some way to the React State Museum


Arthur Gunn

πŸ’» πŸ’‘

Jason Lengstorf

πŸ“–

Marco Afonso

πŸ’» πŸ’‘

Robert DeLuca

πŸ’» πŸ’‘

stereobooster

πŸ“–

Juan David Castro

πŸ’» πŸ“– πŸ’‘

Iurii Kyrylenko

πŸ’»

Charles Lowell

πŸ’»

Jakub Wadas

πŸ’» πŸ“–

Anton Rusinov

πŸ’» πŸ’‘

Miklos Bertalan

πŸ’»

Gant Laborde

πŸ’» πŸ“– πŸ’‘ πŸ“ ⚠️

Tyler Reitz

πŸ’» πŸ“–

Daniel Zlotin

πŸ’» πŸ’‘ ⚠️

Nuno Jesus

🎨

Alek Merani

πŸ’» πŸ“–

Ole Christian Eidheim

πŸ’» πŸ“–

Haz

πŸ’»

Stephen Mathieson

πŸ“–

Christoph Benjamin Weber

πŸ› πŸ’»

Aaron Yoshitake

πŸ’»

IniZio

πŸ’»

Ryan Linton

πŸ’»

Joe Duran

πŸ’»

Minh Tran

πŸ’»

Tudor Pavel

⚠️

Lubos Belak

πŸ“–

Ryan

πŸ’»

Niko Salminen

πŸ’»

J.C. Hiatt

πŸ’‘

doniyor2109

πŸ’»

marcelkalveram

πŸ’» πŸ€”

Alex Lewis

πŸ“–

Steven Langbroek

πŸ›

Kevin

πŸ’» πŸ“–

Lubos Belak

πŸ›

Will Schmid

πŸ’» πŸ“–

Solomon Ayoola

πŸ’» πŸ“–

Dominik Ferber

πŸ“–

Will Caulfield

πŸ’»

Gleb

πŸ’» πŸ“–

Pawel Sas

πŸ’»

Lubos Belak

πŸ›

Imre Osswald

πŸ’»

Frontend Dev

πŸ’» πŸ“– πŸ’‘

This project follows the all-contributors specification. Contributions of any kind welcome!

reactstatemuseum's People

Contributors

airandfingers avatar amerani avatar chimon2000 avatar cowboyd avatar danielzlotin avatar dependabot[bot] avatar dferber90 avatar diegohaz avatar gantman avatar glebhihoho avatar gunn avatar inizio avatar ioss avatar iurii-kyrylenko avatar jchiatt avatar jlengstorf avatar juandc avatar kriswep avatar marcelkalveram avatar minhtc avatar mpaarating avatar msteckyefantis avatar robdel12 avatar rusinovanton avatar sasweb avatar solkimicreb avatar taviroquai avatar tudorpavel avatar vadistic avatar willcaul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

reactstatemuseum's Issues

Immer react native example

The immer implementation has no RN counterpart.

Actually, I would like to work on that myself 😁

Awesome integration tests

A single command to make sure all examples work, and that if they have tests that they pass.

It could also check the Readme to make sure there are no missing links.

Sounds like some basic JavaScript and good first issue.

Is there a talk with this?

I'm hoping that this repo will also (eventually) come with a wunderbar conference-recorded talk. What say you, savage?

Add React Easy state example

Its so easy. Tutorial.

Its always the same:

import React from 'react'
import { store, view } from 'react-easy-state'

const items = store({
    allItems: [/* ...stuff */],
    addItem({ newItem }) {
        items.allItems.concat([newItem])
    }
})

const Component = view(() => (
    <div>
        <h2>{items.allItems}</h2>
        <button onClick={items.addItem("new item :D")}>Add Item</button>
    </div>
))

So, PR?

Logo

Hi, first congrats for your project.
I like to contribute with graphic designs, in opensource projects, so if you need something from me like a logotype or something else just say it, Im here ready to help you.
Greetings!
Nuno Jesus

Remove reduxx

There should be no place in any of our communities for people like this:

image

Update Script

Keeping this museum up to date:

Would be great to have a small script that can run through and execute updtr on all the libraries to get them on the latest versions of React etc. Also, ideally a report letting us know which libraries are falling behind and failed to update.

Maintaining 20+ libs by hand is unreasonable, this script will need to exist.

Add Rematch example

Rematch is a simpler alternative to Redux. It uses react-redux for connecting react with rematch 😝. Works fine with redux-devtools.

Comparison with Redux (taken from the purpose) page:

Redux Rematch
simple setup β€Ž β€Žβœ”
less boilerplate β€Žβœ”
readability β€Žβœ”
configurable β€Žβœ” β€Žβœ”
redux devtools β€Žβœ” β€Žβœ”
generated action creators β€Ž β€Žβœ”
global dispatch β€Ž β€Žβœ”
async thunks β€Žasync/await

PR?

React/mobx example does not compile

After a yarn && yarn start

Failed to compile.

./src/Components/addItem.js
Syntax error: Unexpected token (6:0)

  4 | import { observer } from "mobx-react";
  5 |
> 6 | @observer
    | ^
  7 | export default class AddItems extends Component {
  8 |   render() {
  9 |     return (

❯❯❯❯ node -v                                                                                                                                                                       ~/C/J/R/R/mobx master
v9.11.1
❯❯❯❯ yarn --version                                                                                                                                                                ~/C/J/R/R/mobx master
1.5.1

Add Reim example

State cannot be easier than Reim, trust me 😏.

You can use it as minimal as

import React from 'react'
import reim from 'reim'
import {context} from 'react-reim'

const {get, set} = reim({name: 'Peter'}).plugin(context())

const App = () =>
  get(s => (
    <input
      value={s.name}
      onChange={ev => set({name: ev.target.value})}
    />
  ))

or go ham and use it like Redux

import React from 'react'
import reim from 'reim'
import {connect} from 'react-reim'

// create a store
const counter = reim({count: 10})

// create a presentational component
const Counter = ({value, increment, decrement}) => (
  <div style={styles.container}>
    <button onClick={decrement}>-</button>
    <div style={styles.counter}>{value}</div>
    <button onClick={increment}>+</button>
  </div>
)

// create a container component
const ConnectedCounter = connect(
  counter,
  ({count}) => ({value: count}),
  ({set}) => ({
    increment: () => set(state => {
      state.count++
    }),
    decrement: () => set(state => {
      state.count--
    })
  })
)(Counter)

export default ConnectedCounter

So, PR?

Add Parket example

https://github.com/ForsakenHarmony/parket

A library to manage application state, heavily inspired by mobx-state-tree

Basic example

import model from 'parket';
// model returns a "constructor" function
const Person = model('Person', { // name is used internally for serialization
  initial: () => ({
    firstname: null,
    lastname: null,
    nested: null,
  }),
  actions: state => ({
    setFirstName (first) {
      state.firstname = first; // no set state, no returns to merge, it's reactiveβ„’
    },
    setLastName (last) {
      state.lastname = last;
    },
    setNested (nested) {
      state.nested = nested;
    },
  }),
  views: state => ({
    fullname: () => `${state.firstname} ${state.lastname}`, // views are computed properties
  }),
});

// merge an object with the initial state
const instance = Person({ firstname: 'Tom' });

// you can subscribe to actions, patches (state updates) and snapshots (full state after actions)
const unsubscribe = instance.onSnapshot(console.log);

// you can unsubscribe by calling the function returned by the listener
// unsubscribe();

instance.setLastName('Clancy');

// views turn into cached getters
console.log(instance.fullname); // 'Tom Clancy'

// nested models also bubble up events to the parent
instance.setNested(Person());

instance.nested.setFirstName('wow');

// you can get a snapshot of the state at any time
// { firstname: 'Tom', lastname: 'Clancy',  nested: { firstname: 'wow', lastname: null, nested: null } }
console.log(instance.getSnapshot());

Add Controllerim example

https://github.com/Niryo/controllerim

A simple, clean and well structured state management library for react

Basic usage example

Note: This is a usage example of sharing data between parent and a direct child, but keep in mind that the child could have been a nested child and everything would have stayed the same.

Inside ParentController.js:

import { Controller } from 'controllerim';

export class ParentController extends Controller {
  constructor(compInstance) {
    super(compInstance);
    this.state = {
      message: 'hello' 
    };
  }
  getMessage() {
    return this.state.message;
  }
  setMessage(value) {
    this.state.message = value;
  }
}

Inside Parent.jsx:

import React, { Component } from 'react';
import { observer } from 'controllerim';
import { ParentController } from './ParentController';

class Parent extends Component {
  componentWillMount() {
    this.controller = new ParentController(this);
  }

  render() {
    return (
      <div>
        <h1>{this.controller.getMessage()}</h1>
        <Child/>
        <button onClick={() => this.controller.setMessage('hello world!')}>Click me to change message</button>
      </div>
    );
  }
};

export default observer(Parent);
/** 
note: If you don't want to use default export, you could export the class directly:
export const Parent = observer( class extends Component {
  ...
  }
);

*/

Inside Child.jsx:

import React, { Component } from 'react';
import { observer} from 'controllerim';
import { ChildController } from './ChildController';

class Child extends Component {
  componentWillMount() {
    this.controller = new ChildController(this);
    this.parentController = this.controller.getParentController('ParentController');
  }

  render() {
    return (
      <div>
        <span>This is a message from parent: {this.parentController.getMessage()}</span>
      </div>
    );
  }
};

export default observer(Child);

NPM lib size list?

Perhaps this awesome table on the main readme should list the NPM costs?

image

I'm not sure that's a fair thing to list? Just thinking it will help kill all that dead space, heh.

Add Unistore example

Unistore from Jason Miller (@developit). Super easy state container for React and Preact.

Example must be something like this:

import { createStore, Provider, connect } from "unistore/full/react"

// Initial State
const store = createStore({ allItems: [/* stuff :D */] })
// Actions
const actions = store => ({
  addItem = state => ({ allItems: state.allItems.concat([/* static new stuff */]) }),
  addItemDynamically = (state, props) => {
    store.setState({ allItems: allItems.concat([props.newItem]) })
  }
})

const App = connect("allItems,otherStuff", actions)(stuff => (
    <div>
        <h2>{stuff.allItems}</h2>
        <button onClick={stuff.addItem}>Add static stuff...</button>
        <button onClick={stuff.addItemDynamically({ newItem: "Pizza!" })}>
            Add Dynamic Pizza!
        </button>
    </div>
))

render(
   <Provider store={store}>
    <App />
  </Provider>,
  window.root
)

So, PR?

pure-store needs cleaning

pure-store example is a little messy. Functions are passed as props that should be accessed by smart components. Someone should refactor pure-store to fit like most other examples.

If it's passed as props, it's a simple as setState, someone can easily move the components to access the state properly.

Add CI

With some green tests from #72 - Now connect up to CI for all PRs.

Update to React Native 0.58.3

Stumbled upon this after listening to the RN podcast. Great job @GantMan, and really pleased to see so many examples in React Native.

I realised that many of them are still on RN 0.55 though, and it might make sense to upgrade them to 0.58.3 (the latest version) as many people (including me) are now on xCode 10 and 0.55 is throwing a lot of errors.

Happy to take care of this, but first wanted to make sure it's something the community is interested in.

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.