{"id":29955003,"url":"https://github.com/foca/stateful.js","last_synced_at":"2025-08-03T17:09:18.117Z","repository":{"id":4420262,"uuid":"5558024","full_name":"foca/stateful.js","owner":"foca","description":"Minimalistic implementation of the State pattern in JavaScript","archived":false,"fork":false,"pushed_at":"2012-08-26T06:52:30.000Z","size":92,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-13T23:31:58.990Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/foca.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2012-08-26T06:38:23.000Z","updated_at":"2018-05-08T16:15:12.000Z","dependencies_parsed_at":"2022-08-31T05:22:05.827Z","dependency_job_id":null,"html_url":"https://github.com/foca/stateful.js","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/foca/stateful.js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foca%2Fstateful.js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foca%2Fstateful.js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foca%2Fstateful.js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foca%2Fstateful.js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/foca","download_url":"https://codeload.github.com/foca/stateful.js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foca%2Fstateful.js/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268578914,"owners_count":24273089,"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","status":"online","status_checked_at":"2025-08-03T02:00:12.545Z","response_time":2577,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2025-08-03T17:09:09.557Z","updated_at":"2025-08-03T17:09:18.106Z","avatar_url":"https://github.com/foca.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Stateful.js\n===========\n\nStateful is an implementation of the [State pattern][1] in JavaScript. Read the\nlinked article to understand why you would apply this instead of using any FSM\nimplementation out there.\n\nExample\n-------\n\nThis is a trivial example, but illustrates how you would use Stateful:\n\n``` javascript\nfunction TrafficLight() {\n    this.state = new Stateful(this, \"stop\", TrafficLight.States);\n}\nTrafficLight.States = {};\n\nTrafficLight.States.stop = {\n    color: \"red\",\n    next: function() {\n        this.state.transition(\"go\");\n    },\n    monitorInfractions: function() {\n        // Turn on the camera and make sure nobody breaks the rules.\n    }\n}\n\nTrafficLight.States.go = {\n    color: \"green\",\n    next: function() {\n        this.state.transition(\"caution\");\n    }\n}\n\nTrafficLight.States.caution = {\n    color: \"yellow\",\n    next: function() {\n        this.state.transition(\"stop\");\n    }\n}\n\nvar light = new TrafficLight();\nlight.color //=\u003e \"red\"\ntypeof light.monitorInfractions //=\u003e \"function\"\nlight.next()\nlight.color //=\u003e \"green\"\ntypeof light.monitorInfractions //=\u003e \"undefined\"\nlight.next()\nlight.color //=\u003e \"yellow\"\ntypeof light.monitorInfractions //=\u003e \"undefined\"\nlight.next()\nlight.color //=\u003e \"red\"\n```\n\nCredits\n-------\n\nInspired by the ruby gem [`state_pattern`][2] by [Daniel Cadenas][3]. Built with\nthe support of [Cubox][4] by [Nicolás Sanguinetti][5].\n\nReleased under an MIT license. Check the attached LICENSE file for details.\n\n[1]: http://sourcemaking.com/design_patterns/state\n[2]: http://rubygems.org/gems/state_pattern\n[3]: http://github.com/dcadenas\n[4]: http://cuboxlabs.com\n[5]: http://github.com/foca\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoca%2Fstateful.js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffoca%2Fstateful.js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoca%2Fstateful.js/lists"}