@babichjacob/finite

0.1.0 • Public • Published

Finite

This library for Svelte is just a small wrapper around the excellent svelte-fsm with small design tweaks to my taste.

💻 Installation

npm install --save-dev @babichjacob/finite

🛠 Usage

Import the finite state machine creating function from @babichjacob/finite and use it just like svelte-fsm, except with the additional __auto helper and implicitly use the first state listed as the initial one:

<script>
  import finite from "@babichjacob/finite";

  /** @param {number} ms */
  const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

  const traffic = finite({
    green: {
      async __auto() {
        await wait(5_000);
        return "yellow";
      },
    },

    yellow: {
      async __auto() {
        await wait(2_000);
        return "red";
      },
    },

    red: {
      async __auto() {
        await wait(5_000);
        return "green";
      },
    },
  });
</script>

<div style:background-color={$traffic}>{$traffic}</div>

😵 Help! I have a question

Create an issue and I'll try to help.

😡 Fix! There is something that needs improvement

Create an issue or pull request and I'll try to fix.

📄 License

MIT

🙏 Attribution

This README was generated with ❤️ by readme-md-generator

/@babichjacob/finite/

    Package Sidebar

    Install

    npm i @babichjacob/finite

    Weekly Downloads

    3

    Version

    0.1.0

    License

    MIT

    Unpacked Size

    7.41 kB

    Total Files

    4

    Last publish

    Collaborators

    • babichjacob