Clone and edit this document
Runkit
Runkit
home page
user forum
new notebook
clone notebook
download notebook
support & documentation
log in
sign up
new notebook
help & feedback
clone this notebook
download this notebook
Sign In
Sign Up
Rematch: Basic Usage
node v4.9.1
version:
master
endpoint
share
tweet
const Rematch = require("rematch").default; class Mutant { constructor(name) { this.name = name; } } class SuperHero extends Mutant { } class Villain extends Mutant { } const Mutants = { Batman: new SuperHero('batman'), Flash: new SuperHero('flash'), Joker: new Villain('joker'), Superman: new SuperHero('superman') } function dangerLevel(mutant) { return Rematch(mutant, [ Rematch.Type(Villain, () => 5), Rematch.Value(Mutants.Flash, () => 0), Rematch.Value(Mutants.Superman, () => 2) ]); }; console.log([ dangerLevel(Mutants.Flash), // 0 dangerLevel(Mutants.Superman), // 2 dangerLevel(Mutants.Joker) // 5 ]) console.log(dangerLevel(Mutants.Batman)) // Error: Rematch.MatchError
Created from: https://runkit.com/npm/rematch
Loading…
no comments
sign in
to comment