question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

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

See original GitHub issue

Is 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:open
  • Created 5 years ago
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
nickschotcommented, Aug 31, 2018

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.

1reaction
snewcomercommented, Sep 5, 2018

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found