Ember.js action bubbles up and skips a route

pablobm

Setup

Imagine an Ember.js app (tried v1.13.9) with this structure:

  1. ApplicationRoute
  2. IndexRoute
  3. IndexController

On the index template, there's simply a button with an action:

<!-- index/template.js -->
<button {{action 'ping' 'index template'}}>index</button>

All routes/controllers handle this action, printing out a message and passing the action up until it reaches ApplicationRoute. Eg, for IndexRoute it is:

// excerpt from index/route.js
actions: {
  ping(from) {
    console.log('IndexRoute^ping from', from);
    return true;
  }
}

This same action can also originate at IndexController:

// excerpt from index/controller.js
thingsHappen() {
  this.send('ping', 'index controller');
}

You can see the code and play with it at these URLs:

Question

When you press the button, the messages show that the action is seen by all three routes/controllers, in order, from the inside bubbling up. However, when the action is sent from IndexController, it skips IndexRoute. Why is this?

Kingpin2k

It's related to the fact that the route hasn't truly been transitioned to yet. So the index route isn't part of the current chain. If you want to make sure the index route has been loaded you can hook up to the transition promise and wait for it to complete before calling your action.

 setupController(controller, model, transition) {
    controller.wake('non attached');
    transition.then(function(){
      controller.wake('attached');
    });
  },

http://ember-twiddle.com/e36c0228967fb4485d27

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Sending action from component to route in ember.js

From Dev

Ember.js - I want an Action event (on="") to trigger when there is a transition to a new Route

From Dev

setting model from action in ember route

From Dev

Trigger Ember Error Substate in Route Action

From Dev

Ember 2 action sent to route instead of component

From Dev

'Ember generate resource' command end up adding this.route() to router.js

From Dev

Ember - How to get route model inside route action

From Dev

Can we route from a component in ember js?

From Dev

Route only loads on page refresh - Ember JS

From Dev

Creating a Lightbox Route in Ember.js

From Dev

Setting the model in a nested route in Ember.js

From Dev

How to reload current route in Ember.js?

From Dev

Find Name of current Route in Ember.js

From Dev

open panel/modal in route - Ember.JS

From Dev

How to generate url for a route in Ember.js

From Dev

Ember js -Model in Application Route not loading

From Dev

order of events in Ember.js (applicationController and route)

From Dev

Ember js version 1: Route hierarchy / activation

From Dev

Find Name of current Route in Ember.js

From Dev

carousel for each product(route) ember js

From Dev

Ember.js Route.setupController with ObjectController

From Dev

Ember js -Model in Application Route not loading

From Dev

Ember.js Route with Wildcard Path

From Dev

In an Ember route how can I check if an action exists?

From Dev

Trigger action on controller from route after model has resolved in Ember

From Dev

Can an Ember component listen for a route's didTransition action?

From Dev

Ember JS | How is ember differentiating Router resource and a route?

From Dev

Ember.js TextField action submits form

From Dev

Ember.js input action get element

Related Related

  1. 1

    Sending action from component to route in ember.js

  2. 2

    Ember.js - I want an Action event (on="") to trigger when there is a transition to a new Route

  3. 3

    setting model from action in ember route

  4. 4

    Trigger Ember Error Substate in Route Action

  5. 5

    Ember 2 action sent to route instead of component

  6. 6

    'Ember generate resource' command end up adding this.route() to router.js

  7. 7

    Ember - How to get route model inside route action

  8. 8

    Can we route from a component in ember js?

  9. 9

    Route only loads on page refresh - Ember JS

  10. 10

    Creating a Lightbox Route in Ember.js

  11. 11

    Setting the model in a nested route in Ember.js

  12. 12

    How to reload current route in Ember.js?

  13. 13

    Find Name of current Route in Ember.js

  14. 14

    open panel/modal in route - Ember.JS

  15. 15

    How to generate url for a route in Ember.js

  16. 16

    Ember js -Model in Application Route not loading

  17. 17

    order of events in Ember.js (applicationController and route)

  18. 18

    Ember js version 1: Route hierarchy / activation

  19. 19

    Find Name of current Route in Ember.js

  20. 20

    carousel for each product(route) ember js

  21. 21

    Ember.js Route.setupController with ObjectController

  22. 22

    Ember js -Model in Application Route not loading

  23. 23

    Ember.js Route with Wildcard Path

  24. 24

    In an Ember route how can I check if an action exists?

  25. 25

    Trigger action on controller from route after model has resolved in Ember

  26. 26

    Can an Ember component listen for a route's didTransition action?

  27. 27

    Ember JS | How is ember differentiating Router resource and a route?

  28. 28

    Ember.js TextField action submits form

  29. 29

    Ember.js input action get element

HotTag

Archive