dimanche 30 août 2015

Ember.js action bubbles up and skips a route

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?




Aucun commentaire:

Enregistrer un commentaire