{"id":21553198,"url":"https://github.com/bbvaengineering/ember-route-promise-chain","last_synced_at":"2025-08-02T11:32:58.705Z","repository":{"id":25701448,"uuid":"105672787","full_name":"BBVAEngineering/ember-route-promise-chain","owner":"BBVAEngineering","description":"A tiny ember-cli addon to enable promise-based hooks upon entering or exiting routes.","archived":false,"fork":false,"pushed_at":"2022-12-08T01:12:10.000Z","size":28327,"stargazers_count":2,"open_issues_count":33,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-07-26T22:28:11.312Z","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/BBVAEngineering.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}},"created_at":"2017-10-03T16:06:55.000Z","updated_at":"2020-09-01T05:35:28.000Z","dependencies_parsed_at":"2023-01-14T03:12:49.800Z","dependency_job_id":null,"html_url":"https://github.com/BBVAEngineering/ember-route-promise-chain","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/BBVAEngineering/ember-route-promise-chain","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BBVAEngineering%2Fember-route-promise-chain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BBVAEngineering%2Fember-route-promise-chain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BBVAEngineering%2Fember-route-promise-chain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BBVAEngineering%2Fember-route-promise-chain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BBVAEngineering","download_url":"https://codeload.github.com/BBVAEngineering/ember-route-promise-chain/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BBVAEngineering%2Fember-route-promise-chain/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268378965,"owners_count":24240907,"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-08-02T02:00:12.353Z","response_time":74,"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-11-24T07:09:47.621Z","updated_at":"2025-08-02T11:32:58.670Z","avatar_url":"https://github.com/BBVAEngineering.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ember-route-promise-chain\n\n[![Build Status](https://travis-ci.org/BBVAEngineering/ember-route-promise-chain.svg?branch=master)](https://travis-ci.org/BBVAEngineering/ember-route-promise-chain)\n[![GitHub version](https://badge.fury.io/gh/BBVAEngineering%2Fember-route-promise-chain.svg)](https://badge.fury.io/gh/BBVAEngineering%2Fember-route-promise-chain)\n[![NPM version](https://badge.fury.io/js/ember-route-promise-chain.svg)](https://badge.fury.io/js/ember-route-promise-chain)\n[![Dependency Status](https://david-dm.org/BBVAEngineering/ember-route-promise-chain.svg)](https://david-dm.org/BBVAEngineering/ember-route-promise-chain)\n[![codecov](https://codecov.io/gh/BBVAEngineering/ember-route-promise-chain/branch/master/graph/badge.svg)](https://codecov.io/gh/BBVAEngineering/ember-route-promise-chain)\n[![Greenkeeper badge](https://badges.greenkeeper.io/BBVAEngineering/ember-route-promise-chain.svg)](https://greenkeeper.io/)\n[![Ember Observer Score](https://emberobserver.com/badges/ember-route-promise-chain.svg)](https://emberobserver.com/addons/ember-route-promise-chain)\n\n## Information\n\n[![NPM](https://nodei.co/npm/ember-route-promise-chain.png?downloads=true\u0026downloadRank=true)](https://nodei.co/npm/ember-route-promise-chain/)\n\nA tiny ember-cli addon to enable promise-based hooks upon entering or exiting routes.\n\n## Usage\n\nInstall the addon with ember-cli.\n\n```javascript\nember install ember-route-promise-chain\n```\n\nCreate a new [instance-initializer](https://guides.emberjs.com/v2.14.0/applications/initializers/) and inject the addon.\n\n```javascript\nimport injectPromiseChain from 'ember-route-promise-chain';\n\nexport function initialize(appInstance) {\n  injectPromiseChain(appInstance);\n}\n\nexport default {\n  name: 'route-promise-chain',\n  initialize\n};\n```\n\nIn order to define a new hook, you can setup your routes as follows:\n\n```javascript\nexport default Ember.Route.extend({\n\n  onEnter() {\n    return [new Promise(resolve =\u003e resolve())];\n  },\n\n  onExit() {\n    return [new Promise(resolve =\u003e resolve())];\n  }\n\n});\n```\n\nBoth hooks are executed when the transition finishes. On leaving routes, `onExit` hooks are executed, and on entering routes `onEnter` hooks are executed.\n\n![Example 1](dots/example_1.png)\n\nAlso, you can setup conditions for your hook to execute. Every condition is evaluated just before `promise` is executed, if the condition returns `false`, `promise` won't be executed.\n\n```javascript\nexport default Ember.Route.extend({\n\n  onEnter() {\n    return [{\n      condition: () =\u003e true,\n      promise: new Promise(resolve =\u003e resolve())\n    }];\n  }\n\n});\n```\n\nOn nested routes, `onExit` hooks are executed in `child-parent` order whilst `onEnter` hooks are executed in `parent-child` order. So, for example, in the next figure,\n\n![Example 2](dots/example_2.png)\n\nhooks, are executed as follows:\n\n* onExit: Child A.A -\u003e Parent A.\n* onEnter: Parent B -\u003e Child B.A.\n\nOr, as follows:\n\n* First, Child A.A, onExit method.\n* Next, Parent A, onExit method.\n* Next, Parent B, onEnter method.\n* Last, Child B.A, onEnter method.\n\nEvery hook must return an array with objects with `promise` property. Optionally, a `condition` property can be used to define conditions for the object. This objects are known as `chains`.\n\nHooks `onEnter` and `onExit`, and properties `promise` and `condition` can be [async](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function) functions.\n\n```javascript\nexport default Ember.Route.extend({\n\n  async onEnter() {\n    return [{\n      condition: () =\u003e !this.get('fetched'),\n      promise: async () =\u003e {\n        const response = await this.fetch();\n\n        this.set('fetched', true);\n      }\n    }];\n  }\n\n});\n```\n\nWhen a chain (`condition` or `promise` properties) returns a rejection, next chains on same hierarchy are not executed.\n\nWhen a chain triggers a transition to another route, next chains on all hierarchies are not executed.\n\nExtending routes can be handy to define some behaviour in order to set promise chains dependencies. On the next example, `my-promise` chain will only execute if `promise-base` chain is not going to be executed.\n\n```javascript\n// File: base.js\nexport default Ember.Route.extend({\n\n    async onEnter() {\n      return [{\n        name: 'promise-base',\n        condition: () =\u003e this.get('shouldFetch'),\n        promise: () =\u003e this.fetch()\n      }];\n    }\n\n});\n\n// File: my-route.js\nexport default BaseRoute.extend({\n\n    async onEnter() {\n      const chains = await this._super();\n\n      return [{\n        name: 'my-promise',\n        condition: () =\u003e !chains[0].condition(),\n        promise: () =\u003e this.myFetch()\n      }].concat(chains);\n    }\n\n});\n```\n\n## Contribute\n\nIf you want to contribute to this addon, please read the [CONTRIBUTING.md](CONTRIBUTING.md).\n\n## Versioning\n\nWe use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/BBVAEngineering/ember-route-promise-chain/tags).\n\n\n## Authors\n\nSee the list of [contributors](https://github.com/BBVAEngineering/ember-route-promise-chain/graphs/contributors) who participated in this project.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbbvaengineering%2Fember-route-promise-chain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbbvaengineering%2Fember-route-promise-chain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbbvaengineering%2Fember-route-promise-chain/lists"}