adopted-ember-addons / adopted-ember-addons/ember-infinity

Is it possible to use `ember-infinity` with `ember-concurrency`?

未关闭
#314 15 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
JavaScript
星标
374
派生
128
PR 合并指标
30 天内没有已合并 PR

描述

Is it possible to use `ember-infinity` with `ember-concurrency` (I am learning `ember` and `javascript`)?

I have the following code in my route:

```javascript

import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { isBlank } from '@ember/utils';
import { task, timeout } from 'ember-concurrency';

const DEBOUNCE_MS = 250;

export default Route.extend(AuthenticatedRouteMixin, {
infinity: service(),

actions: {
doNothing() {
return false;
}
},
contactTask: task(function *(params) {
if (isBlank(params)) { return []; }
yield timeout(DEBOUNCE_MS);
let contact = yield this.infinity.model('contact', params);
return contact;
}).restartable(),
model(params) {
/*
* Copied from:
* Replacing your Route models with Ember Concurrency Tasks:
* https://medium.com/@AveryBloom/async-or-swim-replacing-your-route-models-with-ember-concurrency-tasks-5a230252893a
* and:
* Debounced Type-Ahead Search:
* http://ember-concurrency.com/docs/examples/autocomplete
*/
return {
contact: this.get('contactTask').perform(params)
};
},
queryParams: {
criteria: {
refreshModel: true
}
}
```

And this in my `hbs` file:
```html
{{#if model.contact.isRunning}}


Loading contact list...


{{else}}
{{#each model.contact.value as |contact|}}


{{#link-to "contact-detail" contact.id}}
{{contact.companyName}}
{{/link-to}}


{{#link-to "contact-detail" contact.id}}
{{contact.title}}
{{contact.firstName}}
{{contact.lastName}}
{{/link-to}}


{{#each contact.addresses as |address|}}
{{contact-address-in-a-table-cell address=address}}
{{/each}}


{{/each}}


{{infinity-loader
infinityModel=model.contact
loadingText='Loading records...'
loadedText='All records loaded.'}}


{{/if}}
```
It is nearly working, but the `infinity-loader` never finishes loading and every request to the server is duplicated.

Any thoughts would be appreciated. Thank you.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。