redwoodjs

1.0.9 • Public • Published

Redwood

Redwood is a small library with examples to enforce coding in the Elm style in React. It's a work in progress and should be treated as such.

Useage

yarn add --exact redwoodjs

or

npm install --exact redwoodjs

Here's a basic counter example -- checkout out some of the other examples too! redwood-counter.js and the app in redwood-todo. You can access these by changing what's commented in index.js.

import React from "react";

import "./styles.css";

import {
  none,
  RedwoodBootstrap,
  RedwoodComponent,
  RedwoodMessage as Msg,
  RedwoodMessageType as Type,
  RedwoodMessageValue as Val
} from "redwoodjs";

const increase = Symbol("increase");
const decrease = Symbol("decrease");

function update(state = { counter: 0 }, cmd = Msg(none)) {
  switch (Type(cmd)) {
    case increase:
      return {
        state: { counter: state.counter + Val(cmd) },
        cmd: none
      };
    case decrease:
      return {
        state: { counter: state.counter - Val(cmd) },
        cmd: none
      };
  }
}

const Counter = RedwoodComponent((props, dispatch) => {
  const { model } = props;

  return (
    <div>
      <div>{model.counter}</div>
      <button onClick={() => dispatch(Msg(increase, 1))}>increase</button>
      <button onClick={() => dispatch(Msg(decrease, 1))}>decrease</button>
    </div>
  );
});

const initialState = { counter: 0 };
RedwoodBootstrap(
  document.getElementById("root"),
  Counter,
  initialState,
  update
).mount();

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.9
    1
    • latest

Version History

Package Sidebar

Install

npm i redwoodjs

Weekly Downloads

1

Version

1.0.9

License

none

Unpacked Size

90.9 kB

Total Files

19

Last publish

Collaborators

  • trezm