{"id":15522357,"url":"https://github.com/nullvoxpopuli/ember-lifecycle-utils","last_synced_at":"2025-04-15T17:00:22.873Z","repository":{"id":42755354,"uuid":"364715143","full_name":"NullVoxPopuli/ember-lifecycle-utils","owner":"NullVoxPopuli","description":"Utils for lifecycle-related things in Ember","archived":false,"fork":false,"pushed_at":"2025-04-13T23:16:15.000Z","size":1255,"stargazers_count":5,"open_issues_count":11,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-15T17:00:04.475Z","etag":null,"topics":[],"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/NullVoxPopuli.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-05T21:55:29.000Z","updated_at":"2022-11-20T10:31:08.000Z","dependencies_parsed_at":"2023-02-10T12:16:11.839Z","dependency_job_id":"64a58011-c692-4f38-8434-533164d8ee7d","html_url":"https://github.com/NullVoxPopuli/ember-lifecycle-utils","commit_stats":{"total_commits":190,"total_committers":6,"mean_commits":"31.666666666666668","dds":"0.10526315789473684","last_synced_commit":"c7039ad222b7f512ceb0b30bff681fb47d807cb7"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NullVoxPopuli%2Fember-lifecycle-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NullVoxPopuli%2Fember-lifecycle-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NullVoxPopuli%2Fember-lifecycle-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NullVoxPopuli%2Fember-lifecycle-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NullVoxPopuli","download_url":"https://codeload.github.com/NullVoxPopuli/ember-lifecycle-utils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249116232,"owners_count":21215142,"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-10-02T10:40:47.687Z","updated_at":"2025-04-15T17:00:22.852Z","avatar_url":"https://github.com/NullVoxPopuli.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ember-lifecycle-utils\n\n[![npm version](https://badge.fury.io/js/ember-lifecycle-utils.svg)](https://badge.fury.io/js/ember-lifecycle-utils)\n[![CI](https://github.com/NullVoxPopuli/ember-lifecycle-utils/actions/workflows/ci.yml/badge.svg?branch=main\u0026event=push)](https://github.com/NullVoxPopuli/ember-lifecycle-utils/actions/workflows/ci.yml)\n\nUtils to reduce boilerplate when working with lifecycles\n\n## Installation\n\n```\nember install ember-lifecycle-utils\n```\n\n\n## Usage\n\n### Vanilla Classes and Destroyables\n\n```js\nimport { withCleanup } from 'ember-lifecycle-utils';\n\nclass Hello {\n  constructor() {\n    withCleanup(this, () =\u003e {\n      window.addEventListener('click', this.handleClick);\n\n      return () =\u003e {\n        window.removeEventListener('click', this.handleClick);\n      }\n    });\n  }\n}\n```\n\nThis can be used to help make even more concise helpers, like:\n\n```js\nfunction useWindowEvent(context, eventName, handler) {\n  withCleanup(context, () =\u003e {\n    window.addEventListener(eventName, 'click', this.handleClick);\n\n    return () =\u003e {\n      window.removeEventListener(eventName, 'click', this.handleClick);\n    }\n  });\n}\n```\n\nSo now the above example would be:\n\n```js\nclass Hello {\n  constructor() {\n    useWindowEvent(this, 'click', this.handleClick);\n    useWindowEvent(this, 'mouseenter', this.handleClick);\n  }\n}\n```\n\n\n\n### Modifiers\n\n\n```js\nimport { eventListeners } from 'ember-lifecycle-utils/modifier';\n\n\nexport default class Hello extends Component {\n  registerListeners = modifier((element) =\u003e {\n    return eventListeners(element.parentElement,\n      ['click', this.onClick],\n      ['mouseenter', this.onHover],\n    );\n  });\n\n  // or shorthand\n  registerListeners = modifier(eventListeners(\n    ['click', this.onClick],\n    ['mouseenter', this.onHover],\n  ));\n\n\n  // ...\n}\n```\n```hbs\n\u003cbutton {{this.registerListeners}}\u003eclick me\u003c/button\u003e\n```\n\n\n\n## Contributing\n\nSee the [Contributing](CONTRIBUTING.md) guide for details.\n\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnullvoxpopuli%2Fember-lifecycle-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnullvoxpopuli%2Fember-lifecycle-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnullvoxpopuli%2Fember-lifecycle-utils/lists"}