• Stars
    star
    793
  • Rank 57,419 (Top 2 %)
  • Language
    JavaScript
  • Created over 9 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A React renderer for Hardware.

React Hardware

Build Status

React Hardware enables you to build firmata-based hardware applications using a consistent developer experience based on JavaScript and React. The focus of React Hardware is on developer efficiency across all the platforms you care about - learn once, write anywhere.

React Hardware is a IoT and Robotics programming framework developed by Dustan Kasten. Being based on firmata, it is capable of providing feature parity with alternative tools such as Johnny-Five.

Note that this is currently alpha software and hasn’t been tested or have many features implemented. It currently supports firmata’s digitalWrite and analogWrite methods. Full support for firmata is coming including an event system to receive feedback from the board and manipulate state as a result of that.

Hello World

The "Hello World" program of microcontrollers is to "blink an LED". The following code demonstrates how this is done naively with React Hardware and how React’s programming model brings composability to the hardware world.

import React from 'react';
import ReactHardware, {Led} from 'react-hardware';

const HIGH = 255;
const LOW = 0;

class Application extends React.Component {
  constructor(props) {
    super(props);
    this.state = {value: 0};
    this._timer = null;
  }

  componentDidMount() {
    this._timer = setInterval(_ => (
      this.setState(prevState => ({value: prevState.value === HIGH ? LOW : HIGH}))
    ), this.props.interval);
  }

  componentWillUnmount() {
    clearInterval(this._timer);
    this._timer = null;
  }

  render() {
    return (
      <Led pin={10} value={this.state.value} />
    );
  }
}

var PORT = '/dev/tty.usbmodem1411';
ReactHardware.render(<Application interval={1000} />, PORT);

While this is unquestionably more code than it’s Johnny-Five or Sketch equivalents, this now gives you the ability to extract the parts of your board into self-contained components and compose these together. In this application we introduced the concept of a flashing LED, hard-coded naively into the global state. Let’s now extract the idea of a flashing LED into something we can share with our team or even on npm.

import React from 'react';
import ReactHardware, {Board, Led} from 'react-hardware';

const HIGH = 255;
const LOW = 0;

class FlashingLed extends React.Component {
  constructor(props) {
    super(props);
    this.state = {value: 0};
    this._timer = null;
    this.defaultProps = {
      interval: 1000,
    };
  }

  componentDidMount() {
    this._timer = setInterval(_ => (
      this.setState(prevState => ({value: prevState.value === HIGH ? LOW : HIGH}))
    ), this.props.interval);
  }

  componentWillUnmount() {
    clearInterval(this._timer);
    this._timer = null;
  }

  render() {
    return (
      <Led {...this.props} value={this.state.value} />
    );
  }
}

class Application extends React.Component {
  render() {
    return (
      <Board>
        <FlashingLed pin={9} />
        <FlashingLed pin={10} />
        <FlashingLed pin={11} />
        <FlashingLed pin={12} />
      </Board>
    );
  }
}

var PORT = '/dev/tty.usbmodem1411';
ReactHardware.render(<Application />, PORT);

Community

There should be #react-hardware channels created on both https://reactiflux.com/ and IRC.

Contributing

The codebase is written in es6 with (sporadic) types and compiled with babel. Follow the existing style when creating changes. Eslint and the flow type checker will be set up shortly. While the project is under heavy active development it would be useful to make an issue discussing your change before making a PR to ensure we aren’t duplicating effort.

License

Copyright (c) 2015 Dustan Kasten | [email protected] Licensed under the MIT license.

More Repositories

1

smoothscroll

Scroll Behavior polyfill
JavaScript
3,849
star
2

tiny-react-renderer

Learn you a React Renderer for Great Good
JavaScript
774
star
3

yellowbox-react

YellowBox renders warnings at the bottom of the app being developed.
JavaScript
67
star
4

arbiter

A lightweight html5 history library for ender.js
JavaScript
17
star
5

component-playground-responsive-iframe

A responsive iframe renderer for the React component playground.
JavaScript
11
star
6

blessed-standup

Blessed UI for team standups, recorded in a google spreadsheet
JavaScript
7
star
7

queryless

Create a mediaquery free stylesheet for archaic browsers
CSS
7
star
8

iamdustan.github.io

HTML
6
star
9

PUI

A lightweight prototype UI library.
JavaScript
5
star
10

bonsai-demos

Article and demos concerning bonsai for node knockout 2012.
JavaScript
5
star
11

slack-imposter

Pretend to be your colleagues!
Rust
4
star
12

esprima-loader

webpack loader to pipe a file’s AST through arbitrary transforms
JavaScript
4
star
13

react-testing-stateless-components

Failing test case of `React.findDOMNode` with stateless function components.
JavaScript
4
star
14

cypress-react-test

JavaScript
3
star
15

redux-devtools-ui

Experimental UI fun for the redux devtools
JavaScript
2
star
16

d8-fun

JavaScript
2
star
17

all-things-open-2016

JavaScript
2
star
18

dotfiles

Lua
2
star
19

parse-vs-ast-startup-time

Kicked off from https://twitter.com/TheLarkInn/status/852252004277682176
JavaScript
2
star
20

babel-plugin-react-isomorphic

Babel plugin to transform react imports to react/lib/ReactIsomorphic
JavaScript
2
star
21

simplegit

A simple, stripped-down git library for nodejs.
JavaScript
2
star
22

reasonexamples_of_ocapic

OCaPIC tutorial examples on ReasonML
OCaml
2
star
23

jadeplate

A jade+stylus standalone template.
JavaScript
2
star
24

cltjs-welcome-to-the-responsive-web

Responsive slide-deck for the October 2011 CltJS meetup.
JavaScript
2
star
25

bs-audio-context

Experimental bucklescript bindings for the WebAudio API
OCaml
1
star
26

postcss-rs

WIP PostCSS compatible parser written in Rust.
Rust
1
star
27

react-ascii

maybe a new toy
1
star
28

slidenator

JavaScript
1
star
29

granger

A modern, lightweight range UI component with an aim towards integration simplicity and accessibility across all input methods.
CoffeeScript
1
star
30

reworkcss_ast_explorer

Rework CSS’s AST Explorer
JavaScript
1
star
31

lendly

Never forget who you borrow your things to again! Part of The Mentorship Project.
JavaScript
1
star