svecosystem / runed

Magical utilities for your Svelte applications (WIP)
https://runed.dev
MIT License
387 stars 21 forks source link

feat: Add FiniteStateMachine #111

Closed idan closed 1 month ago

idan commented 1 month ago

Update: per @Hugos68 feedback, I converted to a class and renamed to FiniteStateMachine. Otherwise, no changes to the initial PR.

Adds a new useFSM rune that allows you to create minimalistic finite state machines.

Ported over from https://github.com/githubnext/tiny-svelte-fsm (which was already MIT, and I'm the author there). I made a couple of minor fixes along the way as well, mostly to enable people to call .debounce in actions and lifecycle handlers.

This PR includes:

✅ Docs with an interactive demo and examples ✅ Tests

Per our conversation in the Svelte Discord:

CleanShot 2024-07-02 at 16 41 57@2x

changeset-bot[bot] commented 1 month ago

🦋 Changeset detected

Latest commit: c9fd7f7d551f4abebedb1931d0a428f8d7136c03

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ----- | ----- | | runed | Minor |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

github-actions[bot] commented 1 month ago
built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
runed ✅ Ready (View Log) Visit Preview c9fd7f7d551f4abebedb1931d0a428f8d7136c03
idan commented 1 month ago

A lil' demo video of the demo at the top of the docs:

https://github.com/user-attachments/assets/fae59bbf-9252-4df5-b9f8-7e8e726b4960

Hugos68 commented 1 month ago

Could you capitalize the types in the example code? It's a typescript convention.

idan commented 1 month ago

@TGlide thanks, what a lovely review.

I fixed all the things except for the generic vs type assertion. I don't have a better idea, but from a DX perspective, I definitely want the current state to be of type StateT not StateT | undefined or anything like that.