javascript - Ember.js action bubbles up and skips a route -
setup
imagine ember.js app (tried v1.13.9) structure:
- applicationroute
- indexroute
- indexcontroller
on index template, there's button action:
<!-- index/template.js --> <button {{action 'ping' 'index template'}}>index</button> all routes/controllers handle action, printing out message , passing action until reaches applicationroute. eg, indexroute is:
// excerpt index/route.js actions: { ping(from) { console.log('indexroute^ping from', from); return true; } } this same action can originate @ indexcontroller:
// excerpt index/controller.js thingshappen() { this.send('ping', 'index controller'); } you can see code , play @ these urls:
- see github gist: https://gist.github.com/pablobm/8fa2b8ae36e875cb9944
- play twiddle: http://ember-twiddle.com/8fa2b8ae36e875cb9944
question
when press button, messages show action seen 3 routes/controllers, in order, inside bubbling up. however, when action sent indexcontroller, skips indexroute. why this?
it's related fact route hasn't been transitioned yet. index route isn't part of current chain. if want make sure index route has been loaded can hook transition promise , wait complete before calling action.
setupcontroller(controller, model, transition) { controller.wake('non attached'); transition.then(function(){ controller.wake('attached'); }); },
Comments
Post a Comment