Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(route-task) option? #89

Open
Luiz-N opened this issue Oct 27, 2016 · 6 comments
Open

(route-task) option? #89

Luiz-N opened this issue Oct 27, 2016 · 6 comments
Labels
feature-request Request for feature

Comments

@Luiz-N
Copy link

Luiz-N commented Oct 27, 2016

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?

@machty
Copy link
Owner

machty commented Jan 23, 2017

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

@mikkopaderes
Copy link

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.

@nullrocket
Copy link

I would really like to see this be a thing.

@webark
Copy link

webark commented Aug 3, 2017

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.

@buschtoens
Copy link
Contributor

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
Copy link
Contributor

buschtoens commented Aug 4, 2017

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"
}}

@maxfierke maxfierke added the feature-request Request for feature label Aug 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for feature
Projects
None yet
Development

No branches or pull requests

7 participants