Skip to content

Instantly share code, notes, and snippets.

@pangratz
Last active November 9, 2020 18:48
Show Gist options
  • Save pangratz/f1e68d0743abdc3fa728e6d4bf94e009 to your computer and use it in GitHub Desktop.
Save pangratz/f1e68d0743abdc3fa728e6d4bf94e009 to your computer and use it in GitHub Desktop.

Revisions

  1. pangratz revised this gist Nov 9, 2020. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -25,8 +25,7 @@
    "connecting": {
    entry: [
    "clean current socket",
    "increase connection counter",
    "check connection attempts"
    "increase connection counter"
    ],
    on: {
    "connection counter OK": {
  2. pangratz created this gist Nov 9, 2020.
    60 changes: 60 additions & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,60 @@

    // Available variables:
    // - Machine
    // - interpret
    // - assign
    // - send
    // - sendParent
    // - spawn
    // - raise
    // - actions
    // - XState (all XState exports)

    const fetchMachine = Machine({
    id: 'fetch',
    initial: 'not connected',
    states: {
    "not connected": {
    on: {
    "connect(ip)": {
    target: "connecting"
    },
    }
    },

    "connecting": {
    entry: [
    "clean current socket",
    "increase connection counter",
    "check connection attempts"
    ],
    on: {
    "connection counter OK": {
    target: "connectToSocketTask running",
    actions: [
    "start timeout task",
    "start connectToSocketTask"
    ]
    },
    "too many connection attempts": "error"
    }
    },

    "connectToSocketTask running": {
    on: {
    "timeout task finished": {
    target: "connecting"
    },

    "connectSocketTask finished": {
    target: "setupSocketConnection"
    }
    }
    },

    "setupSocketConnection": {},

    "error": {}
    }
    });