{"id":18552541,"url":"https://github.com/andrejewski/ember-subscription","last_synced_at":"2026-05-02T02:34:33.886Z","repository":{"id":68511636,"uuid":"81977948","full_name":"andrejewski/ember-subscription","owner":"andrejewski","description":"Ember event handling that sucks less","archived":false,"fork":false,"pushed_at":"2017-02-28T15:59:43.000Z","size":70,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-15T11:13:32.524Z","etag":null,"topics":["ember","ember-addon","event-emitter","event-management","javascript"],"latest_commit_sha":null,"homepage":null,"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/andrejewski.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-14T18:48:23.000Z","updated_at":"2019-12-24T01:07:36.000Z","dependencies_parsed_at":"2023-03-11T03:48:56.500Z","dependency_job_id":null,"html_url":"https://github.com/andrejewski/ember-subscription","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/andrejewski/ember-subscription","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Fember-subscription","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Fember-subscription/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Fember-subscription/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Fember-subscription/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrejewski","download_url":"https://codeload.github.com/andrejewski/ember-subscription/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Fember-subscription/sbom","scorecard":{"id":192814,"data":{"date":"2025-08-11","repo":{"name":"github.com/andrejewski/ember-subscription","commit":"81a0a3a544b93234c728e8c400815ebdc8e92d44"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":1.7,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/4 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":"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":"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":"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":"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":"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":"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: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":"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":"Vulnerabilities","score":0,"reason":"135 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw","Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25","Warn: Project is vulnerable to: GHSA-pp7h-53gx-mx7r","Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7","Warn: Project is vulnerable to: GHSA-p6mr-pxg4-68hx","Warn: Project is vulnerable to: GHSA-832h-xg76-4gv6","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-cwfw-4gq5-mrqx","Warn: Project is vulnerable to: GHSA-g95f-p29q-9xw4","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-9vvw-cc9w-f27h","Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c","Warn: Project is vulnerable to: GHSA-h6ch-v84p-w6p9","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-4gmj-3p3h-gm8h","Warn: Project is vulnerable to: GHSA-rv95-896h-c2vc","Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx","Warn: Project is vulnerable to: GHSA-qrmc-fj45-qfc2","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-mpcf-4gmh-23w8","Warn: Project is vulnerable to: GHSA-9qj9-36jm-prpv","Warn: Project is vulnerable to: GHSA-xf7w-r453-m56c","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-44pw-h2cw-w3vq","Warn: Project is vulnerable to: GHSA-jp4x-w63m-7wgm","Warn: Project is vulnerable to: GHSA-c429-5p7v-vgjp","Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj","Warn: Project is vulnerable to: GHSA-6x33-pw7p-hmpq","Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37","Warn: Project is vulnerable to: GHSA-4hpf-3wq7-5rpr","Warn: Project is vulnerable to: GHSA-f522-ffg8-j8r6","Warn: Project is vulnerable to: GHSA-2pr6-76vf-7546","Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx","Warn: Project is vulnerable to: GHSA-896r-f27r-55mw","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-282f-qqgm-c34q","Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695","Warn: Project is vulnerable to: GHSA-fvqr-27wr-82fm","Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574","Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm","Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9","Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm","Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw","Warn: Project is vulnerable to: GHSA-2m96-9w4j-wgv7","Warn: Project is vulnerable to: GHSA-h726-x36v-rx45","Warn: Project is vulnerable to: GHSA-6vfc-qv3f-vr6c","Warn: Project is vulnerable to: GHSA-7px7-7xjx-hxm8","Warn: Project is vulnerable to: GHSA-x5pg-88wf-qq4p","Warn: Project is vulnerable to: GHSA-p9wx-2529-fp83","Warn: Project is vulnerable to: GHSA-5v2h-r2cx-5xgj","Warn: Project is vulnerable to: GHSA-rrrm-qjm4-v8hf","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-wrvr-8mpx-r7pp","Warn: Project is vulnerable to: GHSA-hxm2-r34f-qmc5","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-446m-mv8f-q348","Warn: Project is vulnerable to: GHSA-8hfj-j24r-96c4","Warn: Project is vulnerable to: GHSA-56x4-j7p9-fcf9","Warn: Project is vulnerable to: GHSA-v78c-4p63-2j6c","Warn: Project is vulnerable to: GHSA-gwg9-rgvj-4h5j","Warn: Project is vulnerable to: GHSA-pc58-wgmc-hfjr","Warn: Project is vulnerable to: GHSA-vvv8-xw5f-3f88","Warn: Project is vulnerable to: GHSA-w9mr-4mfr-499f","Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g","Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p","Warn: Project is vulnerable to: GHSA-m5h6-hr3q-22h5","Warn: Project is vulnerable to: GHSA-ph34-pc88-72gc","Warn: Project is vulnerable to: GHSA-m6cx-g6qm-p2cx","Warn: Project is vulnerable to: GHSA-x8qc-rrcw-4r46","Warn: Project is vulnerable to: GHSA-4328-8hgf-7wjr","Warn: Project is vulnerable to: GHSA-93f3-23rq-pjfp","Warn: Project is vulnerable to: GHSA-pw54-mh39-w3hc","Warn: Project is vulnerable to: GHSA-xgh6-85xh-479p","Warn: Project is vulnerable to: GHSA-76c9-3jph-rj3q","Warn: Project is vulnerable to: GHSA-q75g-2496-mxpp","Warn: Project is vulnerable to: GHSA-6fx8-h7jm-663j","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-gqgv-6jq5-jjj9","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-6g33-f262-xjp4","Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6","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-4rq4-32rv-6wp6","Warn: Project is vulnerable to: GHSA-64g7-mvw6-v9qj","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-2m39-62fm-q8r3","Warn: Project is vulnerable to: GHSA-mf6x-7mm4-x2g7","Warn: Project is vulnerable to: GHSA-38h8-x697-gh8q","Warn: Project is vulnerable to: GHSA-j44m-qm6p-hp7m","Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9","Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh","Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36","Warn: Project is vulnerable to: GHSA-52f5-9888-hmc6","Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v","Warn: Project is vulnerable to: GHSA-qhv9-728r-6jqg","Warn: Project is vulnerable to: GHSA-g7q5-pjjr-gqvp","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3","Warn: Project is vulnerable to: GHSA-xc7v-wxcw-j472","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-5v72-xg48-5rpm","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","Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh"],"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-16T21:08:48.600Z","repository_id":68511636,"created_at":"2025-08-16T21:08:48.600Z","updated_at":"2025-08-16T21:08:48.600Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32521081,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-02T01:12:54.858Z","status":"online","status_checked_at":"2026-05-02T02:00:05.923Z","response_time":132,"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","event-emitter","event-management","javascript"],"created_at":"2024-11-06T21:14:29.772Z","updated_at":"2026-05-02T02:34:33.861Z","avatar_url":"https://github.com/andrejewski.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"**RELOCATED: Ember Subscription had been moved to [MyPureCloud/ember-subscription](https://github.com/MyPureCloud/ember-subscription). Please send all issues and pull requests to that repository.**\n\n# Ember Subscription\n\nEmber event handling that sucks less.\n\n```sh\nember install ember-subscription\n```\n\n## Summary\n\nWe should provide a good, consistent approach to handling the bookkeeping involved\nwith subscribing to events from `Ember.Evented` and `EventEmitter` objects and jQuery events.\n\n## Motivation\n\nWe are providing this mixin because maintaining event driven code is hard\nenough even without the bookkeeping pitfalls. This mixin supports un/subscribing\nto both Ember's `Evented`, node's `EventEmitter`, and jQuery events. Any place where\nemitter-style event handlers are setup is a good place to use this mixin.\n\nThe subscription mixin does two things:\n\n- It wraps jQuery event handlers in `run()` and binds the provided event\n  handler to the object that calls the mixin.\n\n- It automatically calls `off` on all event handlers when the object's\n  `willDestroy` or `willDestroyElement` hooks are triggered.\n\nThis is good because the bookkeeping (remembering to detach the listener, bind\nthe event handler to the component) is handled for us.\n\n## Detailed design\n\nBetter to show a usage example first:\n\n```js\nimport Ember from 'ember';\nimport { SubscriptionMixin } from 'ember-subscription';\n\nconst {\n  on,\n  inject,\n  Component\n} = Ember;\n\nconst WeBrTcThing = Component.extend(SubscriptionMixin, {\n  wEbRtC: inject.service(),\n\n  WEBrtcEvents: on('didInsertElement', function () {\n    const service = this.get('wEbRtC');\n    const proxy = this.subscribeTo(service);\n    proxy.on('phoneCallReceived', this.handlePhoneCall, 'received');\n  }),\n\n  handlePhoneCall (eventType) {\n    Ember.assert('partial application example:', eventType === 'received');\n    // do something\n  }\n});\n```\n\nThings to note:\n\n- The service is wrapped, not modified in any way. The subscription mixin is\n  the intermediary which will track all the handlers. The service/emitter needs\n  no special logic.\n\n- The mixin provides a `subscribeTo()` method. This is the main method the\n  mixin exposes to keep the API surface small. The `subscribeTo(target, service)` returns\n  an object with chain-able methods (`eventNames` is space separated names):\n\n  * `on(eventNames: string, handler: function, ...partialArgs: [any])`\n\n  * `one(eventNames: string, handler: function, ...partialArgs: [any])`\n\n  * `off(eventNames: string, handler: function, ...partialArgs: [any])`\n\n- We don't need to call `off()` here. Any open subscriptions are closed on the\n  `willDestroyElement` hook.\n\n### Shorthand syntax\n\nThe `subscribeTo` is flexible to different handling styles, but we can add\nmore turtles: the `subscribe` and `subscribeOnce` functions.\n\n```js\nimport Ember from 'ember';\nimport {\n  subscribe,\n  subscribeOnce,\n  SubscriptionMixin\n} from 'ember-subscription';\n\nimport sockets from '../fake/socket-emitter'\n\nconst WeBrTcThing = Ember.Component.extend(SubscriptionMixin, {\n  wEbRtC: Ember.inject.service(),\n\n  handlePhoneCall: subscribe('wEbRtC', 'phoneCallReceived', function () {\n    // do something\n  }),\n\n  socketsConnected: subscribeOnce(sockets, 'connected', function () {\n    // do something once\n  })\n});\n```\n\nThings to note:\n\n- **This is preferred.** Everything is in one place. We don't need one method to attach and one to\n  call, instead it is all one method which is equivalent to the above. Except\n  for the partial application bit which is not supported here.\n\n- We used string `\"wEbRtC\"` but can also pass an actual event emitter instead.\n  A string is used internally like `this.get(\"wEbRtC\")` so it does not have to\n  be a service, it could also be an emitter.\n\n- `subscribe` and `subscribeOnce` bind on `didInsertElement` for components and\n  `init` for everything else. For completeness, here are their function signatures:\n\n   * `subscribe(emitter: string | emitter, eventNames: string, handler: function)`\n\n   * `subscribeOnce(emitter: string | emitter, eventNames: string, handler: function)`\n\n### jQuery handlers\n\nThere are special functions for dealing with jQuery event handlers in your components.\nThey are `subscribe$()`, `subscribeOnce$()`, and `subscribeTo$()`. These act just like\ntheir emitter counterparts except they accept selectors instead.\n\n```js\nimport Ember from 'ember'\n\nconst {\n  run,\n  Component\n} = Ember\n\nexport default Component.extend({\n  didInsertElement () {\n    this._super(...arguments)\n    const startCallHandler = event =\u003e {\n      // Ember needs to put this in the run loop\n      run(() =\u003e this.startCall(event))\n    }\n    this.$().on('click', '.call-button', startCallHandler)\n    run.schedule('afterRender', () =\u003e {\n      // we shouldn't set in didInsertElement\n      this.set('startCallHander', startCallHandler)\n    })\n  },\n\n  willDestroyElement () {\n    this._super(...arguments)\n    const startCallHandler = this.get('startCallHandler')\n    this.$('.call-button').off('click', startCallHandler)\n    this.set('startCallHandler', null)\n  },\n\n  startCall (event) {\n    // start the call\n  }\n})\n```\n\nThis plain Ember is equivalent to:\n\n```js\nimport Ember from 'ember'\nimport {\n  subscribe$,\n  SubscriptionMixin\n} from 'ember-subscription'\n\nexport default Ember.Component.extend(SubscriptionMixin, {\n  startCall: subscribe$('.call-button', 'click', function (event) {\n    // start the call\n  })\n})\n```\n\n## Considerations\n\nThe subscription mixin has a very small API. It unifies differences\nbetween Ember.Evented and EventEmitter behind the scenes so there is only one\ncorrect way to use it. Some further considerations:\n\n### Ember Objects friendly\n\nBy default, handlers are attached on `init` and detached on `willDestroy`.\nFor components however, handlers are attached on `didInsertElement` and\n`willDestroyElement` which are the preferred events.\n\n### Code locality\n\nWe do not need to remember to detach handlers, so we can put our subscription\nand handler logic closer together in the code. There was a lot of reason to\nstuff `init()` and `willDestroy()` with side-effects, but we can keep\nrelated code in one place now and not worry about it (as much).\n\n### Not a silver bullet\n\nThe mixin does not solve the problem of temporary event handling. Life-long\nevents are fine but it is important to remember that handlers will only be\nautomatically cleaned up when the component is destroyed. Any sooner and use of\nthe `subscribeTo(...).off()` method is necessary.\n\n### Debugging events\n\nThis mixin gives us another nice quality: event handler debugging sucks less.\nThis is because we store all subscriptions per component.\nA given object's subscriptions are accessible via `subscriptionsFor(object)`.\n\n```js\nimport {subscriptionsFor} from 'ember-purecloud-components/utils/subscription';\nconst subscriptions = subscriptionsFor(myObject);\n```\n\nIf you want to see if an object is listening to any emitter, check the\nsubscription array which contains subscriptions of this shape:\n\n```js\n{\n  metadata: {\n    source: Ember.Evented | EventEmitter | String,\n    eventNames: String,\n    eventHandler: Function,\n    rawHandler: Function // what you passed in\n  },\n  attach: Function, // adds the listener to the source\n  detach: Function  // removes the listener from the source\n}\n```\n\n## Contributing\n### Installation\n\n* `git clone` this repository\n* `npm install`\n* `bower install`\n\n### Running\n\n* `ember server`\n* Visit your app at http://localhost:4200.\n\n### Running Tests\n\n* `npm test` (Runs `ember try:testall` to test your addon against multiple Ember versions)\n* `ember test`\n* `ember test --server`\n\n### Building\n\n* `ember build`\n\nFor more information on using ember-cli, visit [http://ember-cli.com/](http://ember-cli.com/).\n\nFollow me on [Twitter](https://twitter.com/compooter) for updates or just for the lolz and please check out my other [repositories](https://github.com/andrejewski) if I have earned it. I thank you for reading.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrejewski%2Fember-subscription","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrejewski%2Fember-subscription","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrejewski%2Fember-subscription/lists"}