samedi 21 décembre 2019

EmberJS: Emit event from Service to Route?

I'd like to be able to emit an event from a service, and setup my application Route to listen and act on that event.

app/services/service-action.js:

export default Ember.Service.extend({
  actionA() {
    this.trigger('actionA');
  }
});

app/routes/application.js:

export default Route.extend({
  serviceAction: service(),

  on('serviceAction.actionA', ()=>{
    console.log('actionA fired from serviceAction');
  })
});

Is this possible? Or is there an alternate design pattern I should use to solve this?




Aucun commentaire:

Enregistrer un commentaire