ember-concurrency icon indicating copy to clipboard operation
ember-concurrency copied to clipboard

(route-task) option?

Open Luiz-N opened this issue 9 years ago • 6 comments

hey @machty impressive addon. An example of passing in a task directly to a component like you did here would be great to have in the docs. (Happy to help with that) Also, I was wondering if it would be possible to define a task in a route then be able to pass that down to child components. Essentially a e-c version of route-action... (route-task) perhaps?

I haven't tried this but could it be possible in the short term to define the tasks in a route then have actions that simply return the raw task. This way one could use route-action closures that simply point to a route defined task?

Luiz-N avatar Oct 27 '16 17:10 Luiz-N

@Luiz-N I'm sorry it's taken me so long to respond.

I suppose that's a good idea given how many people use ember-route-action-helper.

One reason I've hesitated on something like this is that it's already a lot easier to pass tasks around than it is to pass actions around (you can just pass a reference to the task to the controller rather than have to use .bind() or closures or something). But yeah, I'd consider something like this.

(hoping for some other feedback from people who also think it's a good idea)

machty avatar Jan 23 '17 11:01 machty

IMO, might be worth the wait to see the RFC for routable components first. In the previous one, I think they were also passing args to the route component similar to setupController. So if we're still headed that way and not like the route-action then at least there wouldn't be any wasted efforts.

mikkopaderes avatar Jan 26 '17 03:01 mikkopaderes

I would really like to see this be a thing.

nullrocket avatar Jul 25 '17 03:07 nullrocket

it's probably going to bite me down the road. But right now I'm giving this a try.

  setupController() {
    this._super(...arguments);

    this.TASK.taskFn = this.TASK.taskFn.bind(this);
    set(this.controller, 'TASK', this.TASK);
  },

where TASK is the concurrency task.

webark avatar Aug 03 '17 19:08 webark

I've created a quick PoC for a route-task helper here: ember-route-task-helper
You can check out a demo here. The source code for the demo is the tests/dummy app.

Give it a try and feel free to open issues for feedback! :)

buschtoens avatar Aug 04 '17 07:08 buschtoens

In the example shown in the README, I use {{get (route-task "deleteUser") "isIdle"}}, but I dislike this kind of syntax. I recommend using the {{with}} helper:

{{#with (route-task "taskOnApplicationRoute" "Freddie") as |task|}}
  {{#if task.isIdle}}
    <button onclick={{perform task "Morecurry"}}>
      Perform taskOnApplicationRoute
    </button>
  {{else}}
    <button onclick={{cancel-all task}}>
      Cancel taskOnApplicationRoute
    </button>

    Running taskOnApplicationRoute
  {{/if}}

  <br>
  task.last.value: {{task.last.value}}<br>
  task.last.error: {{task.last.error}}<br>
{{/with}}

Or even better, only use {{route-task}} to pass tasks as attributes to components.

{{task-aware-button
  task=(route-task "deleteUser" model)
  idleLabel=(concat "Delete " model.name)
  runningLabel="Cancel deletion"
}}

buschtoens avatar Aug 04 '17 08:08 buschtoens