Is it possible to use `ember-infinity` with `ember-concurrency`?
See original GitHub issueIs it possible to use ember-infinity
with ember-concurrency
(I am learning ember
and javascript
)?
I have the following code in my route:
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:
{{#if model.contact.isRunning}}
<tr valign="top">
<td colspan="3">
Loading contact list...
</td>
</tr>
{{else}}
{{#each model.contact.value as |contact|}}
<tr valign="top">
<td>
{{#link-to "contact-detail" contact.id}}
{{contact.companyName}}
{{/link-to}}
</td>
<td>
{{#link-to "contact-detail" contact.id}}
{{contact.title}}
{{contact.firstName}}
{{contact.lastName}}
{{/link-to}}
</td>
<td>
{{#each contact.addresses as |address|}}
{{contact-address-in-a-table-cell address=address}}
{{/each}}
</td>
</tr>
{{/each}}
<tr>
<td colspan="3">
{{infinity-loader
infinityModel=model.contact
loadingText='Loading records...'
loadedText='All records loaded.'}}
</td>
</tr>
{{/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 Analytics
- State:
- Created 5 years ago
- Comments:15 (5 by maintainers)
Top Results From Across the Web
Is it possible to use `ember-infinity` with `ember-concurrency`
I have been searching for answers to this, but can't find anything: It is working correctly without ember-concurrency, but then I lose theĀ ......
Read more >ember-model-select - npm Package Health Analysis - Snyk
The addon composes ember-power-select, ember-infinity and ember-concurrency to provide an easy to use generic model select box based onĀ ...
Read more >Awaiting Events / Conditions - ember-concurrency
In addition to pausing the execution of a task until a yielded promise resolves, it's also possible to pause the execution of a...
Read more >Creating ember-model-select: why and how? - Nick Schot
For the second improvement I wanted to use ember-infinity as it was ... being loaded by using our ember-concurrency task's derived state.
Read more >ember-infinity - npm
Start using ember-infinity in your project by running `npm i ember-infinity`. ... Load Previous Pages; Ember Concurrency Usage; Testing.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Iāve been using ember-infinity in a similar way recently. The pattern works really well. šfor service based infinity models!
Itās not immediately clear from the README yet that this kind of stuff is possible. Iād say thatās mainly because the README only focusses on using infinity in the model hook.
Just to comment on the
yield
example for e-c, thatās just meant as a debounce so you donāt completely spam your API while typing.@scottkidder @nickschot @pkimber I think yaāll are onto something š. Would anybody like to put up a PR in the README/or paste a shortened version here to show what is possible with e-c and components? I think it would be useful to put this towards the top based on what yaāll are saying!! Perhaps we will move the content to a wiki if it makes sense.
Separately, Iāll put up a PR to add navigation to various sections b/c scrolling through the whole README kinda is painful.