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

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

Build:
DEFAULT BRANCH: master
Ran 13 Jan 2019 04:25PM UTC
Files 8
Run time 2s
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

13 Jan 2019 04:24PM UTC coverage: 98.969% (+0.1%) from 98.837%
41.1

push

travis-ci-com

taras
Add union types: (#8)

* 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 = ... (continued)

29 of 30 branches covered (96.67%)

Branch coverage included in aggregate %.

67 of 67 relevant lines covered (100.0%)

175.34 hits per line

Source Files on job 41.1
  • Tree
  • List 0
  • Changed 4
  • Source Changed 4
  • Coverage Changed 3
Coverage ∆ File Lines Relevant Covered Missed Hits/Line Branch Hits Branch Misses
  • Back to Build 8
  • Travis Job 41.1
  • a399f2f4 on github
  • Prev Job for on master (#34.1)
  • Next Job for on master (#46.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