Giter VIP home page Giter VIP logo

react-elmish-example's Introduction

React Elmish Example

This is my personal attempt to understand Elm Architecture better and show how it can be imitated by React components. I'd also like to better understand its strengths and weaknesses.

This specific repository currently has just one example with a few components:

  • A counter component
  • A list component enhancer
  • An action log component enhancer
  • This lets us render a list of counters...
  • ... with action log!
  • ... and undo/redo!

Note that the state lives at the top of the application.

Running

It's up on Github Pages.

You can also

git clone https://github.com/gaearon/react-elmish-example.git
cd react-elmish-example
npm install
npm start
open http://localhost:3000

Sorry, no hot reloading this time!

License

MIT

react-elmish-example's People

Contributors

gaearon 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

react-elmish-example's Issues

How would you pass actions up to the parent?

First off, very cool example.

I'm playing around with this pattern on a help form. The form has its typical onChange events that update the state, etc. But what happens when the form is submitted? How do I get that information up to the parent?

Right now I'm having to parse through all the action messages and delegate them to the project updater. This is pretty tedious.

let Help = {
  view: function({state, dispatch}) {
    return (
      state.success ? 
        <HelpFormSuccess state={state} dispatch={dispatch}/> : 
        <HelpForm state={state} dispatch={dispatch}/>
    )
  },
  update: function(state=initialState, action) {
    switch (action.type) {
      case ON_ERROR:
        //...
      case VALIDATE_AND_SUBMIT:
        //...
      case ON_CHANGE:
        return HelpForm.update(state, action)
      default:
        return state
    }
  }
}

It would be cool it there was a way to indicate whether an action is meant to be dispatched to itself, or up to the parent. How does Elm deal with this? I understand this is just a toy example, but its really cool and I think it would be really power if its done right.

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.