{"id":13807116,"url":"https://github.com/knownasilya/ember-data-tasks","last_synced_at":"2025-04-15T19:43:08.536Z","repository":{"id":57223681,"uuid":"83099021","full_name":"knownasilya/ember-data-tasks","owner":"knownasilya","description":"An alternative Ember Data store that returns Ember Concurrency tasks instead of promises.","archived":false,"fork":false,"pushed_at":"2019-01-30T18:13:18.000Z","size":88,"stargazers_count":25,"open_issues_count":2,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-09T22:44:10.897Z","etag":null,"topics":["ember","ember-addon","ember-concurrency","ember-data","tasks"],"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/knownasilya.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-02-25T02:05:54.000Z","updated_at":"2024-05-30T02:48:00.000Z","dependencies_parsed_at":"2022-08-30T02:10:20.097Z","dependency_job_id":null,"html_url":"https://github.com/knownasilya/ember-data-tasks","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knownasilya%2Fember-data-tasks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knownasilya%2Fember-data-tasks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knownasilya%2Fember-data-tasks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knownasilya%2Fember-data-tasks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/knownasilya","download_url":"https://codeload.github.com/knownasilya/ember-data-tasks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249141040,"owners_count":21219410,"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","ember-concurrency","ember-data","tasks"],"created_at":"2024-08-04T01:01:21.072Z","updated_at":"2025-04-15T19:43:08.483Z","avatar_url":"https://github.com/knownasilya.png","language":"JavaScript","readme":"# ember-data-tasks\n\nAn alternative Ember Data store that returns [Ember Concurrency] tasks instead of promises.\n\n## Install\n\n```sh\nember install ember-data-tasks\n```\n\nThis addon comes in three phases:\n\n- [Phase 1: Store Override](#phase-1-store-override)\n- [Phase 2: Model Override](#phase-2-model-override)\n- Phase 3: Custom Endpoints, like ember-api-actions, but with tasks (coming soon).\n\n## Phase 1: Store Override\n\nBy overriding the store with a mixin, we extend the behavior of methods on the store, like `store.findRecord('post', 1)`.\n\n### Setup\n\nOverride your existing store, by creating a new store (or use your existing one, if you have it):\n\n```sh\nember g service store\n```\n\nOpen `app/services/store.js` and modify it to:\n\n```js\nimport DS from 'ember-data';\nimport TaskStoreMixin from 'ember-data-tasks/mixins/task-store';\n\nexport default DS.Store.extend(TaskStoreMixin);\n```\n\n### Use\n\nNow you can use your Ember Data store like before, and nothing has changed, since this\nstore is backwards compatible, due to the fact that `tasks` also adhere to the promise spec.\n\nBut you didn't come here for the same old, you want immediate results.\nTo take advantage of the benefits of tasks, you will have to wrap your store responses in a hash.\n\nThe example below will hit `afterModel` after the backend has resolved with data:\n\n```js\nimport Ember from 'ember';\n\nexport default Ember.Route.extend({\n  model() {\n    return this.store.findAll('post');\n  }\n});\n```\n\nBut if you want immediate responses, do the following, and `afterModel` will\nbe hit immediately:\n\n```js\nimport Ember from 'ember';\n\nexport default Ember.Route.extend({\n  model() {\n    return {\n      postsTask: this.store.findAll('post')\n    };\n  }\n});\n```\n\nThen you can utilize the `task` in your template like so:\n\n```hbs\n\u003cul\u003e\n  {{#if model.postsTask.isRunning}}\n    Loading your posts..\n  {{else}}\n    {{#each model.postsTask.value as |post|}}\n      \u003cli\u003e{{post.name}}\u003c/li\u003e\n    {{/each}}\n  {{/if}}\n\u003c/ul\u003e\n```\n\nThis seems like a slight annoyance at first, due to the extra level of nesting, but\nin the end if you build ambitious apps, you will most likely return multiple\ntasks, and would have used `Ember.RSVP.hash` anyway, if working with promises.\n\n**Note: You can unwrap the task hash in `setupController`, if it really bothers you.**\n\n## Phase 2: Model Override\n\nThis phase allows you to enable tasks for methods like `model.save()`.\n\n### Setup\n\nOpen `app/models/my-model.js` and modify it to:\n\n```js\nimport DS from 'ember-data';\nimport TaskModelMixin from 'ember-data-tasks/mixins/task-model';\n\nexport default DS.Model.extend(TaskModelMixin, {\n  // your model definition\n});\n```\n\nYou'd have to do this for every model, and if you have few, that should be easy.\nFor those that have many models, you can do the following:\n\nReopen the `DS.Model` in your `app/app.js` file.\n\n```js\nimport Ember from 'ember';\nimport Resolver from './resolver';\nimport loadInitializers from 'ember-load-initializers';\nimport config from './config/environment';\n// Add these two imports\nimport DS from 'ember-data';\nimport TaskModelMixin from 'ember-data-tasks/mixins/task-model';\n\nlet App;\n\nEmber.MODEL_FACTORY_INJECTIONS = true;\n\nApp = Ember.Application.extend({\n  modulePrefix: config.modulePrefix,\n  podModulePrefix: config.podModulePrefix,\n  Resolver\n});\n\nloadInitializers(App, config.modulePrefix);\n\n// Add this model reopen\nDS.Model.reopen(TaskModelMixin);\n\nexport default App;\n```\n\n### Use\n\nNow you can call `model.reload()`, `model.save()`, and `model.destroyRecord()` and get\ntasks back instead of promises.\n\n[Ember Concurrency]: http://ember-concurrency.com\n","funding_links":[],"categories":["Packages"],"sub_categories":["Job queues"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknownasilya%2Fember-data-tasks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fknownasilya%2Fember-data-tasks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknownasilya%2Fember-data-tasks/lists"}