@dandan wrote:
I’m having troubles with Evented throwing an odd bug when used with a Promise.
I’ve made a simple service to subscribe to events in my components. It just extends Evented, so we can trigger and listen to events.
import Service from "@ember/service"; import Evented from "@ember/object/evented"; export default Service.extend(Evented);
When used with the following:
return new RSVP.Promise(resolve => { service.trigger("transitionStart"); resolve(); })
I get the following error:
Cannot read property 'apply' of undefined at sendEvent (vendor.js:20489) ... which is: method.apply(target, params); at Class.trigger (vendor.js:32860)
Even if I rewrite the Service to be more explicit, I get the same error:
export default Service.extend(Evented, { transitionStart: function() { this.trigger("transitionStart"); }, transitionEnd: function() { this.trigger("transitionEnd"); }, init() { this._super(...arguments); this.on("transitionStart", function() { //for testing, listen to the event here console.log("we received the transition Start event"); }); } });
and call it via:
return new RSVP.Promise(resolve => { service.transitionStart(); resolve(); })
Why isn’t sendEvent working for me in this context?
trigger(name, ...args) { sendEvent(this, name, args); },
Posts: 1
Participants: 1