• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

microstates / trafficlight / 37 / 1
99%
master: 99%

Build:
Build:
LAST BUILD BRANCH: tm/add-chat-badge
DEFAULT BRANCH: master
Ran 09 Jan 2019 10:04PM UTC
Files 8
Run time 0s
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

09 Jan 2019 09:48PM UTC coverage: 99.038%. First build
37.1

push

travis-ci-com

cowboyd
Add union types:

One of the original conceptions of microstates was that it should be
an effective way to use modelling your application state using state
machines. One of the key insights was that there are strong analogues
between types and states, where each type corresponds to a distinct
state. So for example, in a light switch state machine, you might have
two types, each descending from a base state:

```javascript

class Switch {
  get isOn() { return false; }
  get isOff() { return false; }

  initialize(value) {
    if (value) {
      return create(On, true);
    } else {
      return create(Off, false);
    }
  }
}

class On extends Switch {
  get isOn() { return true; }

  flip() {
    return create(Off, false);
  }
}

class Off extends Switch {
  get isOff() { return true; }

  flip() {
    return create(On, true);
  }
}
```

This let's you start in one state, and gracefully transition to
another.

```javascript
create(Switch, off).flip().flip().flip() //=> On {}
create(Switch, off).flip().flip().flip().isOn //=> true
```

This is really excellent to use, but expressing it can be fiddly to
get right sometimes. It very much has the feeling of "stitching"
together microstates to achive this nice thing, rather than something
that microstates is expressly there to do.

What we really want is to be able to succinctly express a set of types
and make sure that they adhere together in the following ways:

1. They all descend from the same superclass (On extends Switch, etc..)
2. They have the appropirate boolean state discriminator
   properties (isOn, isOff)
3. The initializers are properly wired together, and contain a
   recursive escape hatch to avoid infinite looping.

This change contains a prototype of a `Union` function that takes a
descriptor and creates a Union type. The union types are based loosely
off of Haskell union types e.g. `data Maybe a = Just a | Nothing`

Where the union type is represented as the superclass, and the
construc... (continued)

32 of 33 branches covered (96.97%)

Branch coverage included in aggregate %.

71 of 71 relevant lines covered (100.0%)

61.66 hits per line

Source Files on job 37.1
  • Tree
  • List 0
  • Changed 0
  • Source Changed 0
  • Coverage Changed 0
Coverage ∆ File Lines Relevant Covered Missed Hits/Line Branch Hits Branch Misses
  • Back to Build 4
  • Travis Job 37.1
  • bc07df85 on github
  • Next Job for on cl/union-types (#39.1)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc