Skip to content

Instantly share code, notes, and snippets.

@erikras
Created April 30, 2021 10:26
Show Gist options
  • Save erikras/cde893307f347e76d09e65bfea24bb65 to your computer and use it in GitHub Desktop.
Save erikras/cde893307f347e76d09e65bfea24bb65 to your computer and use it in GitHub Desktop.

ReScript

type event = Increment | Decrement

export type transition = (. event) => unit

export createTestMachine = (. transition: transition) => {
  // Return a function that calls the transition (contrived, I know)
  let doTransition = (event:event) => transition(. event)
  doTransition
}

JavaScript

Perfect!

function createTestMachine(transition) {
  return function ($$event) {
    return transition($$event);
  };
}

TypeScript

Why a function that takes both the transition and the event?!?!

const $$toJS914395812: { [key: string]: any } = {"0": "Increment", "1": "Decrement"};

const $$toRE914395812: { [key: string]: any } = {"Increment": 0, "Decrement": 1};

// @ts-ignore: Implicit any on import
import * as bugBS__Es6Import from './bug.bs';
const bugBS: any = bugBS__Es6Import;

// tslint:disable-next-line:interface-over-type-literal
export type event = "Increment" | "Decrement";

// tslint:disable-next-line:interface-over-type-literal
export type transition = (_1:event) => void;

export const createTestMachine: (_1:transition, _2:event) => void = function (Arg1: any, Arg2: any) {
  const result = bugBS.createTestMachine(function (Arg11: any) {
      const result1 = Arg1($$toJS914395812[Arg11]);
      return result1
    }, $$toRE914395812[Arg2]);
  return result
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment