{"id":13805575,"url":"https://github.com/workmanw/ember-diff-attrs","last_synced_at":"2025-03-16T14:30:55.056Z","repository":{"id":14947091,"uuid":"77345504","full_name":"workmanw/ember-diff-attrs","owner":"workmanw","description":"An ember-addon that provides a dry way to track component attribute changes using lifecycle hooks.","archived":false,"fork":false,"pushed_at":"2023-03-04T03:27:51.000Z","size":2409,"stargazers_count":26,"open_issues_count":16,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-05-03T16:18:50.031Z","etag":null,"topics":["ember","ember-addon"],"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/workmanw.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"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}},"created_at":"2016-12-25T22:40:07.000Z","updated_at":"2023-03-28T17:30:46.000Z","dependencies_parsed_at":"2024-01-09T05:01:26.949Z","dependency_job_id":"230d328e-0741-4c20-9ca7-8e4d56c23c57","html_url":"https://github.com/workmanw/ember-diff-attrs","commit_stats":{"total_commits":27,"total_committers":12,"mean_commits":2.25,"dds":0.7037037037037037,"last_synced_commit":"c5b14d0b1f94dcf5378e0c539cd1635ecf46a49a"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/workmanw%2Fember-diff-attrs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/workmanw%2Fember-diff-attrs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/workmanw%2Fember-diff-attrs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/workmanw%2Fember-diff-attrs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/workmanw","download_url":"https://codeload.github.com/workmanw/ember-diff-attrs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243818195,"owners_count":20352629,"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":["ember","ember-addon"],"created_at":"2024-08-04T01:01:02.515Z","updated_at":"2025-03-16T14:30:54.649Z","avatar_url":"https://github.com/workmanw.png","language":"JavaScript","readme":"# ember-diff-attrs\n\nThis addon was spun out of a discussion on [emberjs/rfcs#191](https://github.com/emberjs/rfcs/pull/191) [Deprecate component lifecycle hook arguments].\n\nember-diff-attrs provides a dry way to track attribute changes using a component's `didReceiveAttrs` lifecycle hook.\n\nPRs, RFCs and comments are welcome!\n\n## ember-did-change-attrs\n\n@GavinJoyce and I (mostly Gavin) created an alternative version of this addon that offers a slightly cleaner API using a mixin instead of a decorator.\n\nSee: [ember-did-change-attrs](https://github.com/workmanw/ember-did-change-attrs)\n\n## Usage\n\n### Shorthand usage\n```javascript\nimport diffAttrs from 'ember-diff-attrs';\n\nexport default Ember.Component.extend({\n  didReceiveAttrs: diffAttrs('email', 'isAdmin', function(changedAttrs, ...args) {\n    this._super(...args);\n\n    if(changedAttrs \u0026\u0026 changedAttrs.email) {\n      let oldEmail = changedAttrs.email[0],\n          newEmail = changedAttrs.email[1];\n      // Do stuff\n    }\n  })\n});\n```\n\nSome quick notes:\n* The function hook provided to `diffAttrs` will **always** be called, even when a tracked attr is not changed.\n* `changedAttrs` will be `null` on the first call.\n\n\n### Extended usage\n\n```javascript\nimport diffAttrs from 'ember-diff-attrs';\n\nexport default Ember.Component.extend({\n  didReceiveAttrs: diffAttrs({\n    keys: ['user', 'isAdmin'],\n    isEqual(key, a, b) {\n      if (key === 'user') {\n        return (a \u0026\u0026 b) ? a.id === b.id : a === b;\n      }\n      return a === b;\n    },\n    hook(changedAttrs, ...args) {\n      this._super(...args);\n\n      if(changedAttrs \u0026\u0026 changedAttrs.user) {\n        let oldUser = changedAttrs.user[0],\n            newUser = changedAttrs.user[1];\n        // Do stuff\n      }\n    }\n  })\n});\n```\n\n\n## Design thoughts / rationales.\n\n* `changedAttrs` null on `init` -- It seems likely that some users will want an alternate behavior for `init` vs `update`. There is no loss of functionality by having `changedAttrs` null on `init` and it's easy to explain, _nothing has actually changed yet_.\n* `changedAttrs` structure -- I followed the precedence started by ember-data (`model.changedAttributes()`).\n\n## Outstanding Questions\n\n### Changed attrs format\n\nI followed ember-data's precedence for representing old and new values (`model.changedAttributes()`). This format has always felt odd to me. I'm more than happy to discuss changing this.\n\n### didUpdateAttrs\n\nSince this addon is implemented as a macro, it cannot easily utilize a component's `init` call to setup. Because of this, we are unable to determine what has changed the first time `didUpdateAttrs` is called.  \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\nFor more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/).\n\nLicense\n------------------------------------------------------------------------------\n\nThis project is licensed under the [MIT License](LICENSE.md).\n","funding_links":[],"categories":["Packages"],"sub_categories":["Component addons"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworkmanw%2Fember-diff-attrs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fworkmanw%2Fember-diff-attrs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworkmanw%2Fember-diff-attrs/lists"}