{"id":18087676,"url":"https://github.com/hiddentao/immutable-state-machine","last_synced_at":"2025-11-04T23:02:51.669Z","repository":{"id":57272869,"uuid":"51369767","full_name":"hiddentao/immutable-state-machine","owner":"hiddentao","description":"Immutable state machine for Javascript with ability to associate extra data with each state. Useful for React.","archived":false,"fork":false,"pushed_at":"2016-09-30T15:11:52.000Z","size":15,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-26T13:39:08.307Z","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/hiddentao.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-09T13:50:59.000Z","updated_at":"2019-07-15T08:41:34.000Z","dependencies_parsed_at":"2022-09-13T22:41:45.228Z","dependency_job_id":null,"html_url":"https://github.com/hiddentao/immutable-state-machine","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/hiddentao/immutable-state-machine","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hiddentao%2Fimmutable-state-machine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hiddentao%2Fimmutable-state-machine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hiddentao%2Fimmutable-state-machine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hiddentao%2Fimmutable-state-machine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hiddentao","download_url":"https://codeload.github.com/hiddentao/immutable-state-machine/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hiddentao%2Fimmutable-state-machine/sbom","scorecard":{"id":464120,"data":{"date":"2025-08-11","repo":{"name":"github.com/hiddentao/immutable-state-machine","commit":"100729bb7679f39c430e82864d414bb61a9dd0ba"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 0/10 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.md:0","Info: FSF or OSI recognized license: MIT License: LICENSE.md:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-19T11:58:55.307Z","repository_id":57272869,"created_at":"2025-08-19T11:58:55.307Z","updated_at":"2025-08-19T11:58:55.307Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":282727657,"owners_count":26717232,"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-11-04T02:00:05.887Z","response_time":62,"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":"2024-10-31T17:04:58.477Z","updated_at":"2025-11-04T23:02:51.647Z","avatar_url":"https://github.com/hiddentao.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Immutable state machine\n\n[![Build Status](https://secure.travis-ci.org/hiddentao/immutable-state-machine.png)](http://travis-ci.org/hiddentao/immutable-state-machine)\n\nA simple yet flexible _immutable_ [finite-state machine](https://en.wikipedia.org/wiki/Finite-state_machine) for Javascript. Great for when building with frameworks like \n[React](https://facebook.github.io/react/).\n\nFeatures:\n\n* Works in Node.js and the browser.\n* Immutability - use simple object equality to check if state changed.\n* Restrict state transitions using from/to rules.\n* Store additional data alongside each state.\n* Very small (\u003c2 KB).\n\n\n## Installation\n\n### CommonJS\n\nInstall using [npm](http://npmjs.org/):\n\n  $ npm install immutable-state-machine\n\n### Browser\n\nInclude the `build/immutableStateMachine.js` script.\n\nIn the browser the library is exposed via the `ImmutableStateMachine` class function.\n\n## How to use\n\n### The basics - states and data\n\nLet's create a machine with two states - `start` and `stop`:\n\n```javascript\nvar Machine = require('immutable-state-machine');\n\n/*\nWe'll have two states - \"start\" and \"stop\"\n*/\nvar m = new Machine([\n  'start',\n  'stop'\n]);\n\nconsole.log( m.getState() );      // \"start\"\nconsole.log( m.getData() );       // null\n```\n\nBy default the first state passed-in (`start`) is the initially active state. \nThe data associated with a state is initially always `null`. \n\nIf needed we can explicitly set the initial state:\n\n```javascript\nvar m = new Machine([\n  'start',\n  {\n    id: 'stop',\n    initial: true,\n  }\n]);\n\nconsole.log( m.getState() );      // \"stop\"\n```\n\nNow let's goto a new state and see what happens:\n\n```javascript\nvar m = new Machine([\n  'start',\n  'start'\n]);\n\nvar m2 = m.goto('stop');\n\nconsole.log( m2 === m );      // false\nconsole.log( m2.getState() ); // \"stop\"\nconsole.log( m.getState() );  // \"start\"\n```\n\nAs expected according to _immutability_, it returned a new instance of the \nmachine, leaving the original unchanged. \n\nInstead, what if we went to the same state?\n\n```javascript\nvar m = new Machine([\n  'start',\n  'start'\n]);\n\nvar m2 = m.goto('start');\n\nconsole.log( m2 === m );      // true\n\nconsole.log( m2.getState() ); // \"start\"\nconsole.log( m2.getData() ); // null\n```\n\nThe same instance gets returned back as expected. But if we goto the same state \nwith different data a new instance will be returned:\n\n```javascript\nvar m = new Machine([\n  'start',\n  'start'\n]);\n\nvar m2 = m.goto('start', {\n  some: 'data'\n});\n\nconsole.log( m2 === m );      // false\n\nconsole.log( m2.getState() ); // \"start\"\nconsole.log( m2.getData() ); // { some: 'data' }\n\nconsole.log( m.getState() ); // \"start\"\nconsole.log( m.getData() ); // null\n```\n\n\n### Restricting transitions\n\nBy default we can transition from any state to any other state.\n\nBut sometimes we want to restrict state-to-state transitions according to \npre-configured rules. We can specify such rules using `from` and `to` arrays:\n\n```javascript\nvar Machine = require('immutable-state-machine');\n\nvar m = new Machine([\n  {\n    id: 'step1',\n    from: [],\n    to: ['step2'],\n  },\n  {\n    id: 'step2',\n    from: ['step1'],\n    to: ['step3'],\n  },\n  {\n    id: 'step3',\n    from: ['step2'],\n    to: ['step4'],\n  },\n  {\n    id: 'step4',\n    from: ['step3'],\n    to: ['step1'],\n  },\n])\n\nconsole.log( m.getState() );    // \"step1\"\n\n// m.goto('step3');  -\u003e Error\n// m.goto('step4');  -\u003e Error\n\nm.goto('step2');\n\n// m.goto('step1');  -\u003e Error\n// m.goto('step4');  -\u003e Error\n\nm.goto('step3');\n\n// m.goto('step1');  -\u003e Error\n// m.goto('step2');  -\u003e Error\n\nm.goto('step4');\n\n// m.goto('step1');  -\u003e Error, because step1 \"from\" is empty array\n// m.goto('step2');  -\u003e Error\n// m.goto('step3');  -\u003e Error\n```\n\nThe above machine allows us transition from `step1` through to `step4` and \nthen nothing else. Note that although we have specified that `step4` may \ntransition _to_ `step1`, we specified an empty _from_ array for `step1` thus \nspecifying that it is not possible to transition to `step1` from another step.\n\n\n### Seamless sub-classing\n\nIf you inherit from `Machine` then all methods will return new instances of \nyour subclass rather than the base class.\n\n```js\nclass MyMachine extends Dummy {}\n  \nvar m = new MyMachine(['start', 'stop']);\n\nvar m2 = m.goto('stop');\n\nconsole.log( m2 instanceof MyMachine ); /* true */\n```\n\n## Building\n\nTo build the code and run the tests:\n\n    $ npm install -g gulp\n    $ npm install\n    $ npm run build\n\n\n## Contributing\n\nContributions are welcome! Please see [CONTRIBUTING.md](https://github.com/hiddentao/immutable-state-machine/blob/master/CONTRIBUTING.md).\n\n## License\n\nMIT - see [LICENSE.md](https://github.com/hiddentao/immutable-state-machine/blob/master/LICENSE.md)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhiddentao%2Fimmutable-state-machine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhiddentao%2Fimmutable-state-machine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhiddentao%2Fimmutable-state-machine/lists"}