0.1.0 ā¢ Published 3 years ago
@babichjacob/finite v0.1.0
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