Giter VIP home page Giter VIP logo

connect-to-stores's Introduction

connectToStores (for alt)

'Higher Order Component' for alt flux that controls the props of a wrapped component via stores.

Alt is an Isomorphic flux implementation.

Check out the API Reference for full in-depth alt docs. For a high-level walk-through on flux, take a look at the Getting Started guide.

Gitter

// @todo Use real badges for this package.
/*
[![NPM version](https://badge.fury.io/js/alt.svg)](http://badge.fury.io/js/alt)
[![Build Status](https://secure.travis-ci.org/goatslacker/alt.svg?branch=master)](http://travis-ci.org/goatslacker/alt)
[![Coverage Status](https://img.shields.io/coveralls/goatslacker/alt.svg?style=flat)](https://coveralls.io/r/goatslacker/alt)
[![Dependency Status](https://david-dm.org/goatslacker/alt.svg)](https://david-dm.org/goatslacker/alt)
[![Download Count](https://img.shields.io/npm/dm/alt.svg?style=flat)](https://www.npmjs.com/package/alt)
[![JS.ORG](https://img.shields.io/badge/js.org-alt-ffb400.svg?style=flat-square)](http://js.org)
*/

How to use

Expects the Component to have two static methods:

  • getStores(): Should return an array of stores.
  • getPropsFromStores(props): Should return the props from the stores.

Using old React.createClass() style:

const MyComponent = React.createClass({
  statics: {
    getStores(props) {
      return [myStore]
    },
    getPropsFromStores(props) {
      return myStore.getState()
    }
  },
  render() {
    // Use this.props like normal ...
  }
})
MyComponent = connectToStores(MyComponent)

Using ES6 Class:

class MyComponent extends React.Component {
  static getStores(props) {
    return [myStore]
  }
  static getPropsFromStores(props) {
    return myStore.getState()
  }
  render() {
    // Use this.props like normal ...
  }
}
MyComponent = connectToStores(MyComponent)

Using ES7 Decorators (proposal, stage 0):

@connectToStores
class MyComponent extends React.Component {
  static getStores(props) {
    return [myStore]
  }
  static getPropsFromStores(props) {
    return myStore.getState()
  }
  render() {
    // Use this.props like normal ...
  }
}

A great explanation of the merits of higher order components can be found at http://bit.ly/1abPkrP

License

MIT

connect-to-stores's People

Contributors

cpsubrian avatar mattkahl avatar mwbennett avatar

Watchers

James Cloos 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.