Latest Socket ResearchMalicious Chrome Extension Performs Hidden Affiliate Hijacking.Details
Socket
Book a DemoInstallSign in
Socket

barracks-react

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

barracks-react

An action dispatcher for unidirectional data flows for React components

Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

barracks-react

An action dispatcher for React that provides for unidirectional dataflows. Intended to be very small and provide a small amount of cognative overhead in providing an "actions up, data down" type model for React. Built on top of barracks. Bonus -- use this with hyperx for a JSX-free, forward compatible version of React!

Usage

const React = require('react')
const ReactDOM = require('react-dom')
const hyperx = require('hyperx')
const html = hyperx(React.createElement)
const br = require('./')
const store = br()

const model = {
  namespace: 'example',
  store: {
    hello: ''
  },
  reducers: {
    setHello: (data, state) => ({hello: data.value})
  }
}

const Main = React.createClass({
  getInitialState: function () {
    return {
      hello: '',
      instance: this
    }
  },
  componentWillMount: function () {
    this.send = store.register(model, this.state.instance)
  },
  componentWillUnmount: function () {
    store.unregister(model)
  },
  handleChange: function (evt) {
    this.send('example:setHello', {value: evt.target.value})
  },
  render: function () {
    return html`<div>
      <h1>Hello, ${this.state.hello}</h1><br>
      <input type="text" value="${this.state.hello}" onChange=${this.handleChange} />
    </div>`
  }
})

const main = React.createElement(Main)
ReactDOM.render(main, document.body)

License

Copyright © 2016 Scripto, licenced under the Apache-2.0 license

Keywords

barracks

FAQs

Package last updated on 01 Sep 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts