NullVoxPopuli / ember-resources

An implementation of Resources. Supports ember 3.28+

Home Page:https://github.com/NullVoxPopuli/ember-resources/blob/main/docs/docs/README.md

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`trackedTask` does not work with newer ec async task format

mydea opened this issue · comments

The new async task format from ember-concurrency is quite cool (https://github.com/machty/ember-concurrency/releases/tag/2.3.2), however it does not seem to work with trackedTask.

My usage:

menuItemsTask = trackedTask(this, this.loadMenuItemsTask, () => []);

loadMenuItemsTask = task(async () => {
  // do something here
});

I get the error:

ember-concurrency.js:71 
 Uncaught (in promise) TypeError: Cannot use 'in' operator to search for 'perform' in undefined
    at task (ember-concurrency.js:71:25)
    at new MainMenuService (menu.js:42:258)

I have see the same error as ^^. Is there a work around here?

Seems to come from here... https://github.com/NullVoxPopuli/ember-resources/blob/main/ember-resources/src/util/ember-concurrency.ts#L67 were task is undefined at the time it is used.

Using this construct worked for me...

define loadMenuItemsTask before trackedTask uses it

loadMenuItemsTask = task(async () => {
  // do something here
});

menuItemsTask = trackedTask(this, this.loadMenuItemsTask, () => []);

I haven't gotten around to it yet, bu the plan is to allow usables to be registered with ember-resources, so ember-concurrency's task could be a trackedTask all on its own like this:

import { task } from 'ember-concurrency';
import { use } from 'ember-resources';

// ...
@use loadMenuItemsTask = task(async () => {
  // do something here
});

But I don't know how to change the type of the returned task to a TaskInstance, so suggestions welcome (and this is partially why I haven't done this yet)

👋 I was also planning on using the trackedTask but faced this same issue.

Latest version should work. Lemme know!

commented

Latest version should work. Lemme know!

Hey, @NullVoxPopuli I'm having this issue currently with ember-resources 5.4.1. Could you explain what should work, please? Moving the trackedTask after the declaration of the task works for me but I am not sure if we want this

Thanks!

What version of ember concurrency are you using?

This is the usage that should work: #611 (comment)

commented

What version of ember concurrency are you using?

Just updated to 4.0.0

This is the usage that should work: #611 (comment)

I can confirm it does work 😄 I was confused by this comment: #611 (comment)

Excellent! I'll close this issue. Thanks!

The other comment is more a dream for a simpler api