{"id":13727044,"url":"https://github.com/ggoodman/fsm","last_synced_at":"2025-10-05T14:45:36.676Z","repository":{"id":57113205,"uuid":"291106367","full_name":"ggoodman/fsm","owner":"ggoodman","description":"Fully typed finite state machine for JavaScript and TypeScript.","archived":false,"fork":false,"pushed_at":"2021-03-25T20:55:03.000Z","size":25,"stargazers_count":48,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-19T05:47:42.427Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ggoodman.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-28T17:27:16.000Z","updated_at":"2024-02-23T19:10:06.000Z","dependencies_parsed_at":"2022-08-21T20:40:31.204Z","dependency_job_id":null,"html_url":"https://github.com/ggoodman/fsm","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ggoodman%2Ffsm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ggoodman%2Ffsm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ggoodman%2Ffsm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ggoodman%2Ffsm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ggoodman","download_url":"https://codeload.github.com/ggoodman/fsm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251493994,"owners_count":21598208,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T01:03:37.104Z","updated_at":"2025-10-05T14:45:31.621Z","avatar_url":"https://github.com/ggoodman.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# @ggoodman/fsm\n\n\u003e Fully typed finite state machine for JavaScript and TypeScript\n\n## Installation\n\n```bash\nnpm install @ggoodman/fsm\n```\n\n## Example\n\nThe example below demonstrates a traffic light that cycles eternally on a timer.\n\n\u003e **Note**: Instead of defining the 'tick' event, we could have called `ctx.transitionTo('red' | 'green' | 'yellow')` directly.\n\n```typescript\nimport { DefineEvent, DefineState, Service } from '@ggoodman/fsm';\n\ntype Red = DefineState\u003c'red'\u003e;\ntype Yellow = DefineState\u003c'yellow'\u003e;\ntype Green = DefineState\u003c'green'\u003e;\n\ntype Tick = DefineEvent\u003c'tick'\u003e;\n\nconst service = Service.define\u003cRed | Yellow | Green, Tick\u003e(\n  (s) =\u003e\n    s\n      .defineState('red', (red) =\u003e\n        red\n          .onEnter((ctx) =\u003e ctx.runAfter(30 * 1000, (ctx) =\u003e ctx.send('tick')))\n          .onEvent('tick', (ctx) =\u003e ctx.transitionTo('green'))\n      )\n      .defineState('green', (red) =\u003e\n        red\n          .onEnter((ctx) =\u003e ctx.runAfter(60 * 1000, (ctx) =\u003e ctx.send('tick')))\n          .onEvent('tick', (ctx) =\u003e ctx.transitionTo('yellow'))\n      )\n      .defineState('yellow', (red) =\u003e\n        red\n          .onEnter((ctx) =\u003e ctx.runAfter(10 * 1000, (ctx) =\u003e ctx.send('tick')))\n          .onEvent('tick', (ctx) =\u003e ctx.transitionTo('red'))\n      ),\n  'red'\n);\n\nservice.onStateChange((state) =\u003e {\n  console.log('State changed to %s', state.id);\n});\nservice.start();\n// State changed to red\n// State changed to green\n// State changed to yellow\n// ...\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fggoodman%2Ffsm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fggoodman%2Ffsm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fggoodman%2Ffsm/lists"}