Opened 8 years ago

Closed 8 years ago

#14799 closed enhancement (wontfix)

on/Evented should support target and currentTarget

Reported by: Marcel Lucas Owned by: Kris Zyp
Priority: undecided Milestone: tbd
Component: Events Version: 1.7.0
Keywords: Cc:
Blocked By: Blocking:

Description

When using custom Events and Evented you will trap into this issue when it comes to bubbling your own events.

I have a class structure that produces deep element trees. Every element is able to fire events - yet build with my very own EventDispatcher? (meets the features of Adobe's ActionScript? 3.0 EventDispatcher? + handler.remove() idea).

I would like to migrate to dojo.Evented if it could handle events in a way that a listener could determine where an Event was fired (event.currentTarget) and from where it was dispatched originally (event.target)).

Attached there is a patch for on.js + test case.

Hope to see something like this in the very near future :)

Attachments (1)

dojo-on-currentTarget.patch (2.1 KB) - added by Marcel Lucas 8 years ago.

Download all attachments as: .zip

Change History (5)

Changed 8 years ago by Marcel Lucas

Attachment: dojo-on-currentTarget.patch added

comment:1 Changed 8 years ago by Marcel Lucas

... and some code that illustrates my use case:

require(["dojo/Evented"], function(Dispatcher){
    var container = new Dispatcher(),
        deepChild = new Dispatcher();

    container.name = "root";
    deepChild.name = "child";

    deepChild.parentNode = container;


    var _onStartHandler = function(e){
            console.log(e.currentTarget.name+" noticed that "+e.target.name+" just started")
         },
        _onFinishHandler = function(e){
            console.log(e.currentTarget.name+" noticed that "+e.target.name+" just finished")
        };

    container.on("onStart", _onStartHandler);
    container.on("onFinish", _onFinishHandler);
    


    deepChild.emit("onStart", {bubbles:true});
    deepChild.emit("onFinish", {bubbles:true});
})

comment:2 Changed 8 years ago by Kris Zyp

You can use |this| to get the current element that received the event. For example:

  container.on("onStart", function(e){
            console.log(this.name+" noticed that "+e.target.name+" just started");
         });

Is that what you are looking for?

comment:3 Changed 8 years ago by Marcel Lucas

Thanks for your quick response. Well my example does not reflect the real world situation (class context) and it feels somewhat dirty to change the scope within a class... I will have some thoughts about it but would recommend to add the currentTarget property.

comment:4 Changed 8 years ago by Kris Zyp

Resolution: wontfix
Status: newclosed
Note: See TracTickets for help on using tickets.