Giter VIP home page Giter VIP logo

thisless-react's Introduction

thisless React

Reactive React application flow, with React, RxJS and Redux.

It is all about...

  • thisless: this cannot be found in examples!

  • Fully Reactive: With RxJS and React Reactive Class, components are made reactive and observable.

  • It's just React: No magic! Use the technique you already know, without learning new library or API and plays well with your existing React apps.

  • Pure View: Completely decouple View from Model, no more Model injection. Code like store.dispatch(action) or store.getState() cannot be found in View.

  • High Performance: Introduce Static Component and Data Binding by default. React will no longer diff entire huge Virtual DOM. See Vjeux's slide Animated โ€” React Performance Toolbox for more details.

Getting started

The building blocks are functions that returning element node and event streams.

function button(props) {
  const clickEv$ = new Rx.Subject();
  const element = (
    <button onClick={clickEv$.onNext.bind(clickEv$)}>
      {props.text}
    </button>
  );

  return {
    element,
    events: {
      clickEv$
    }
  }
}

Compose these functions and eventually you will get a function with root element node and event streams of the app.

const store = configureStore();
const { state$ } = store;

const {
  element: App,
  events
} = app(state$);

ReactDOM.render(App, mountNode);

And then write code to handle these event streams, like dealing with store or interacting with the browser.

function handleEvent(store, events) {
  events.clickIncreaseButton$.subscribe(() => {
    store.dispatch(/* ... */);
  });
}

handleEvent(store, events);

That's it!

See examples for complete app code.

Tip about Redux middleware

There is no restrictions on how to use Redux in your thisless React app, but I highly recommend using RxJS streams to replace middleware, they handles async operations well and in this way your application flow will become more clear and straightforward (and you write less code!).

Feedbacks are welcome!

Feel free to discuss via opening issues or send pull requests!

Inspirations

Cycle.js: I borrowed lots of concepts from it.

Angular: Don't create components all the time, element + function is good enough to get the job done.

License

The MIT License (MIT)

thisless-react's People

Contributors

jas-chen avatar

Watchers

 avatar  avatar

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.