{"id":31551463,"url":"https://github.com/heycarsten/ember-fsm","last_synced_at":"2025-10-04T18:56:37.013Z","repository":{"id":14944891,"uuid":"17669487","full_name":"heycarsten/ember-fsm","owner":"heycarsten","description":"[Maintenance Mode] A promise-aware finite state machine implementation for Ember","archived":false,"fork":false,"pushed_at":"2018-12-20T12:19:37.000Z","size":395,"stargazers_count":39,"open_issues_count":3,"forks_count":14,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-09-26T11:50:42.354Z","etag":null,"topics":["ember","ember-addon","fsm","javascript","state-machine"],"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/heycarsten.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":"2014-03-12T14:20:23.000Z","updated_at":"2024-05-30T02:32:23.000Z","dependencies_parsed_at":"2022-08-30T14:50:12.061Z","dependency_job_id":null,"html_url":"https://github.com/heycarsten/ember-fsm","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/heycarsten/ember-fsm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heycarsten%2Fember-fsm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heycarsten%2Fember-fsm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heycarsten%2Fember-fsm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heycarsten%2Fember-fsm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/heycarsten","download_url":"https://codeload.github.com/heycarsten/ember-fsm/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heycarsten%2Fember-fsm/sbom","scorecard":{"id":463062,"data":{"date":"2025-08-11","repo":{"name":"github.com/heycarsten/ember-fsm","commit":"875d3adbcfeddbf1a0d178522e11682f2b8e1ae4"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":1.9,"checks":[{"name":"Code-Review","score":1,"reason":"Found 4/26 approved changesets -- score normalized to 1","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":"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":"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":"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":"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":"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":"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":"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":"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":"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":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"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":"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"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 8 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"104 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-6chw-6frg-f759","Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-c6rq-rjc2-86v2","Warn: Project is vulnerable to: GHSA-wxhq-pm8v-cw75","Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq","Warn: Project is vulnerable to: GHSA-ff7x-qrg7-qggm","Warn: Project is vulnerable to: GHSA-j4f2-536g-r55m","Warn: Project is vulnerable to: GHSA-r7qp-cfhv-p84w","Warn: Project is vulnerable to: GHSA-3gx7-xhv7-5mx3","Warn: Project is vulnerable to: GHSA-rv95-896h-c2vc","Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx","Warn: Project is vulnerable to: GHSA-74fj-2j2h-c42q","Warn: Project is vulnerable to: GHSA-pw2r-vq6v-hr8c","Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc","Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp","Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3","Warn: Project is vulnerable to: MAL-2023-462","Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97","Warn: Project is vulnerable to: GHSA-q42p-pg8m-cqh6","Warn: Project is vulnerable to: GHSA-w457-6q6x-cgp9","Warn: Project is vulnerable to: GHSA-62gr-4qp9-h98f","Warn: Project is vulnerable to: GHSA-f52g-6jhx-586p","Warn: Project is vulnerable to: GHSA-2cf5-4w76-r9qv","Warn: Project is vulnerable to: GHSA-3cqr-58rm-57f8","Warn: Project is vulnerable to: GHSA-g9r4-xpmj-mj65","Warn: Project is vulnerable to: GHSA-q2c6-c6pm-g3gh","Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44","Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988","Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj","Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j","Warn: Project is vulnerable to: GHSA-6x33-pw7p-hmpq","Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37","Warn: Project is vulnerable to: GHSA-6c3j-c64m-qhgq","Warn: Project is vulnerable to: GHSA-gxr4-xjj5-5px2","Warn: Project is vulnerable to: GHSA-jpcq-cgw6-v4j6","Warn: Project is vulnerable to: GHSA-2pr6-76vf-7546","Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-675m-85rw-j3w4","Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp","Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574","Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm","Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695","Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw","Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9","Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm","Warn: Project is vulnerable to: GHSA-46fh-8fc5-xcwx","Warn: Project is vulnerable to: GHSA-h5mp-5q4p-ggf5","Warn: Project is vulnerable to: GHSA-h726-x36v-rx45","Warn: Project is vulnerable to: GHSA-6vfc-qv3f-vr6c","Warn: Project is vulnerable to: GHSA-f9cm-qmx5-m98h","Warn: Project is vulnerable to: GHSA-7wpw-2hjm-89gp","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-fhjf-83wg-r2j9","Warn: Project is vulnerable to: GHSA-pc58-wgmc-hfjr","Warn: Project is vulnerable to: GHSA-vvv8-xw5f-3f88","Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p","Warn: Project is vulnerable to: GHSA-76c9-3jph-rj3q","Warn: Project is vulnerable to: GHSA-6fx8-h7jm-663j","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j","Warn: Project is vulnerable to: GHSA-rhx6-c78j-4q9w","Warn: Project is vulnerable to: GHSA-xfhp-gmh8-r8v2","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg","Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p","Warn: Project is vulnerable to: GHSA-4g88-fppr-53pp","Warn: Project is vulnerable to: GHSA-4jqc-8m5r-9rpr","Warn: Project is vulnerable to: GHSA-fxwf-4rqh-v8g3","Warn: Project is vulnerable to: GHSA-25hc-qcg6-38wj","Warn: Project is vulnerable to: GHSA-xfhh-g9f5-x4m4","Warn: Project is vulnerable to: GHSA-qm95-pgcg-qqfq","Warn: Project is vulnerable to: GHSA-cqmj-92xf-r6r9","Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9","Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw","Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc","Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh","Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p","Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36","Warn: Project is vulnerable to: GHSA-4wf5-vphf-c2xc","Warn: Project is vulnerable to: GHSA-52f5-9888-hmc6","Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v","Warn: Project is vulnerable to: GHSA-7p7h-4mm5-852v","Warn: Project is vulnerable to: GHSA-cf4h-3jhx-xvhq","Warn: Project is vulnerable to: GHSA-v2p6-4mp7-3r9v","Warn: Project is vulnerable to: GHSA-g78m-2chm-r7qv","Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q","Warn: Project is vulnerable to: GHSA-h6q6-9hqw-rwfv","Warn: Project is vulnerable to: GHSA-5fg8-2547-mr8q","Warn: Project is vulnerable to: GHSA-crh6-fp67-6883","Warn: Project is vulnerable to: GHSA-72mh-269x-7mh5","Warn: Project is vulnerable to: GHSA-h4j5-c7cj-74xg"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-19T11:41:21.961Z","repository_id":14944891,"created_at":"2025-08-19T11:41:21.962Z","updated_at":"2025-08-19T11:41:21.962Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278358488,"owners_count":25973949,"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-10-04T02:00:05.491Z","response_time":63,"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":["ember","ember-addon","fsm","javascript","state-machine"],"created_at":"2025-10-04T18:56:35.462Z","updated_at":"2025-10-04T18:56:36.941Z","avatar_url":"https://github.com/heycarsten.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ember FSM\n\n:warning: :warning: :warning:\n\n**Maintenance Mode**\n\nEmber FSM was a lot of fun to develop 4 years ago when this all made a lot of sense to me, it's still used in some places and I will continue to maintain it to prevent apps from breaking. If you think the Ember community still needs a library like this with newer/better features please fork it and I will let people know where to go! Thanks for understanding :slightly_smiling_face:\n\n:warning: :warning: :warning:\n\n#### A promise-aware finite state machine implementation for Ember\n\n[A wild (and current) traffic light demo appears!](https://ember-twiddle.com/7136a752d42aee13c1072c96480494f4)\n\n```js\nimport FSM from 'ember-fsm';\n\nlet trafficSignal = FSM.Machine.create({\n  events: {\n    cycle: {\n      transitions: [\n        { initialized: 'red' },\n        { red: 'green' },\n        { green: 'amber' },\n        { amber: 'red' }\n      ]\n    },\n\n    powerDown: {\n      transition: { $all: 'off' }\n    }\n  }\n});\n\ntrafficSignal.get('currentState');\n// \"initialized\"\n\ntrafficSignal.send('cycle');\ntrafficSignal.get('currentState');\n// \"red\"\n\ntrafficSignal.send('cycle');\ntrafficSignal.get('currentState')\n// \"green\"\n```\n\n## Getting Started\n\nInstall as an Ember Addon\n\n```\nember install ember-fsm\n```\n\n### Do you need this?\n\nTry really hard not to need it, if you need it, I'm sorry. -- @heycarsten\n\n### Defining a State Machine\n\n```js\nimport FSM from 'ember-fsm';\n\nlet SleepyFSM = FSM.Machine.extend({\n  // Here is where you define your state machine's state-specific configuration.\n  // This section is optional.\n  states: {\n    // The default initial state is \"initialized\"\n    initialState: 'awake'\n\n    // If you'd like, you can choose to explicitly define the names of your\n    // states:\n    knownStates: ['sleeping', 'angry', 'awake', 'initialized', 'failed'],\n\n    // You can define global per-state callbacks, they will fire whenever the\n    // state will be entered, was entered, will be exited, or was exited.\n    sleeping: {\n      willEnter() { },\n      didEnter() { },\n      willExit() { },\n      didExit() { }\n    }\n  },\n\n  // Here's where you define your state machine's events, it is required.\n  events: {\n    sleep: {\n      // You can define global per-event callbacks. These will fire for any\n      // transition before or after this event.\n      before() { },\n      after() { },\n\n      // This is where the event's transitions are defined, it is also aliased\n      // to \"transition\". It can accept either a single object like one in the\n      // array below, or an array of transition definition objects:\n      transitions: [\n        { awake: 'sleeping', doUnless: 'unableToSleep' },\n        { awake: 'angry', doIf: 'unableToSleep' },\n        { sleeping: '$same' }\n      ]\n    },\n\n    // By default this error event is injected into your state machine for you,\n    // you can override it and provide your own transitions and callbacks if\n    // you'd like.\n    error: {\n      transition: { $all: 'failed' }\n    }\n  }\n});\n```\n\n### State Macros\n\nFor the sake of less typing (and less chances of introducing failure) the\nfollowing macros can be used in transition definitions:\n\n| Macro      | Description                   |\n|:-----------|:------------------------------|\n| `$all`     | Expands to all known states.  |\n| `$same`    | Expands to the same state as the from state. `transition: { sleeping: '$same' }` |\n| `$initial` | Expands to the initial state. |\n\n### Transition Guarding\n\nYou can specify that a transition be excluded or included in the event using\n`doIf` or `doUnless`. Consider `SleepyFSM` above, if we set `unableToSleep` to\n`true` then when we send in the `sleep` event, it will transition to the state\n`angry` because the transition `{ awake: 'sleeping' }` will be excluded from\nthe list.\n\n`doIf` and `doUnless` are aliased to `guard` and `unless` respectively.\n\n### Transition Events \u0026 Callbacks\n\nGiven the `SleepyFSM` example above, suppose we ran the following:\n\n```js\nlet fsm = SleepyFSM.create();\nfsm.send('sleep');\n```\n\nHere is the series of transition events that will occurr and the corresponding\ncallbacks that will run and where they can be defined:\n\n| Current State | Is Active | Event                    | Runs callbacks                        |\n|:--------------|:----------|:-------------------------|:--------------------------------------|\n| awake         | **false** | `beforeEvent`            | `before` on events and transitions    |\n| awake         | **true**  | `_activateTransition_`   | _internal_                            |\n| awake         | **true**  | `willExit`               | `willExit` on states and transitions  |\n| awake         | **true**  | `willEnter`              | `willEnter` on states and transitions |\n| sleeping      | **true**  | `_setNewState_`          | _internal_                            |\n| sleeping      | **true**  | `didExit`                | `didExit` on states and transitions   |\n| sleeping      | **true**  | `didEnter`               | `didEnter` on states and transitions  |\n| sleeping      | **false** | `_deactivateTransition_` | _internal_                            |\n| sleeping      | **false** | `afterEvent`             | `after` on events and transitions     |\n\nSome of the event names above also have aliases:\n\n| Event         | Aliases           |\n|:--------------|:------------------|\n| `beforeEvent` | `before`          |\n| `afterEvent`  | `after`           |\n| `didEnter`    | `enter`, `action` |\n| `didExit`     | `exit`            |\n\n### Asynchronicity In Callbacks\n\nIf callbacks return a promise, the next callback in the chain will not fire\nuntil the promise is resolved. The return value of callbacks is stored in the\ntransition's `resolutions` object. Likewise, rejections are stored in the\n`rejections` object of the transition.\n\n### Namespacing States\n\n`ember-fsm` doesn't provide true sub-state support, but you can namespace your\nstates. For example, suppose a portion of your state workflow is related in\nsome way; you can prefix those states with a namespace:\n\n* ready\n* uploading.requestingUrl\n* uploading.sendingData\n* processing.enqueuing\n* processing.working\n* finished\n\nWhen you define states like this, Ember.FSM automatically generates the\nfollowing boolean accessor properties for you:\n\n* isInReady\n* isInUploading\n* isInUploadingRequestingUrl\n* isInUploadingSendingData\n* isInProcessing\n* isInProcessingEnqueuing\n* isInProcessingWorking\n* isInFinished\n\n### Stateful Mixin\n\nWhen it comes to using `ember-fsm` in your application, you'll almost always\nwant to use `FSM.Stateful` over sub-classing `FSM.Machine`. This way\nyou can formalize a state workflow around something like file uploads where you\nmight have to incorporate three different proceesses into on user experience.\n\nNote: States and events are renamed in the mixin to `fsmStates` and `fsmEvents`\nrespectively, to avoid conflict with core Ember properties.\n\nBuilding these sorts of workflows implicitly as-you-code-along can be a recipie\nfor massive sadness. So why be sad? Formalize that workflow! Here's an example\nof how adding `ember-fsm` to a controller can remove a lot of the\ntedious parts of workflow managment:\n\n```js\nimport Ember from 'ember';\nimport FSM from 'ember-fsm';\n\n// controllers/upload.js\nexport default Ember.Controller.extend(FSM.Stateful, {\n  needs: 'notifier',\n\n  actions: {\n    uploadFile(file) {\n      this.set('file', file);\n      this.sendStateEvent('addFile');\n    }\n  },\n\n  fsmStates: {\n    initialState: 'nofile'\n  },\n\n  fsmEvents: {\n    addFile: {\n      transitions: {\n        from:   ['nofile', 'failed'],\n        to:     'ready',\n        before: 'checkFile',\n      }\n    },\n\n    startUpload: {\n      transitions: {\n        from:     'ready',\n        to:       'uploading',\n        before:   'getUploadURL',\n        didEnter: 'performUpload',\n        after:    'finishedUpload'\n      }\n    },\n\n    finishUpload: {\n      transition: { uploading: 'nofile', didEnter: 'reset' }\n    }\n  },\n\n  reset() {\n    this.set('file', null);\n  },\n\n  checkFile() {\n    let file = this.get('file');\n\n    if (file.size \u003e 0) {\n      return;\n    } else {\n      this.get('controllers.notifier').warn('file must have content');\n      FSM.reject(); // A helper for throwing an error\n    }\n  },\n\n  getUploadURL() {\n    let fileName = this.get('file.name');\n\n    let xhr = Ember.$.ajax('/api/signed_uploads', {\n      type: 'put',\n      data: { file: { name: fileName } }\n    });\n\n    xhr.then((payload) =\u003e {\n      Ember.run(() =\u003e {\n        this.set('uploadToURL', payload.signed_upload.url);\n      });\n    });\n\n    return xhr; // Causes transition to block until promise is settled\n  },\n\n  performUpload() {\n    return Ember.$.ajax(this.get('uploadToURL'), {\n      type: 'put',\n      data: this.get('file')\n    });\n  },\n\n  finishedUpload() {\n    this.get('controllers.notifier').success('Upload complete');\n    this.sendStateEvent('finishUpload');\n  }\n});\n```\n\n### Running tests\n\n* `ember test` – Runs the test suite on the current Ember version\n* `ember test --server` – Runs the test suite in \"watch mode\"\n* `ember try:each` – Runs the test suite against multiple Ember versions\n\n### Running the dummy application\n\n* `ember serve`\n* Visit the dummy application at [http://localhost:4200](http://localhost:4200).\n\n## Thanks\n\n- [@catz](https://github.com/catz) for updating the addon to work with Ember 3.3+\n- [@hhff](https://github.com/hhff) for the continued support and feedback\n- [@joliss](https://github.com/joliss) for all her hard work on [broccoli](https://github.com/joliss/broccoli)\n- [@rpflorence](https://github.com/rpflorence) for all of his work on [broccoli-dist-es6-module](https://github.com/rpflorence/broccoli-dist-es6-module)\n- [@obrie](https://github.com/obrie) for the Ruby [state_machine](https://github.com/pluginaweek/state_machine) gem, which was my first introduction to state machines\n- [@tildeio](https://github.com/tildeio) \u0026 crew for [RSVP](https://github.com/tildeio/rsvp.js) and [Ember](https://github.com/emberjs/ember.js)\n- My coworkers and friends [@elucid](https://github.com/elucid) [@ghedamat](https://github.com/ghedamat) [@drteeth](https://github.com/drteeth) [@minusfive](https://github.com/minusfive) for reviewing and fiddling with the stuff I make\n- [Unspace](https://unspace.ca) for understanding open source and caring about open source\n- [@ssured](https://github.com/ssured) for adding the ability to define callbacks as inline functions\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheycarsten%2Fember-fsm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fheycarsten%2Fember-fsm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheycarsten%2Fember-fsm/lists"}