kimoa / svg-edit

Automatically exported from code.google.com/p/svg-edit
MIT License
3 stars 0 forks source link

svgCanvas.bind(event, function) overwrites old event handlers #941

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
The function that is (no pun intended) bound to svgCanvas.bind (not defined in 
the SvgCanvas class but added dynamically) does not permit to bind more than 
one handler to an event like 'change'. Instead, it replaces the old handler and 
returns it to the caller.

It looks like this

    c.bind = function(event, f) {
      var old = events[event];
        events[event] = f;
        return old;
    };

Is that intentional? I did not expect that behaviour and it sent me bug-hunting 
for an afternoon.

Original issue reported on code.google.com by mor...@wissenba.ch on 2 Apr 2012 at 4:35

GoogleCodeExporter commented 8 years ago
If you say it's not defined in svgcanvas class then it's probably not meant for 
public consumption? It sure looks deliberately overwritten (return old 
function).

What is your usecase? You can use svgCanvas.runExtensions() to broadcast events 
from within your extension, and you can already listen to events so I'm not 
sure why you need to bind?

Original comment by asyazwan on 3 Apr 2012 at 1:12

GoogleCodeExporter commented 8 years ago
My use case  is loading an SVG image via the 'url' query parameter, and have an 
extension notified when it arrives to parse it and do something.

I've now switched to doing this via the standard extension mechanism listening 
to 'elementChanged' and checking if '#svgcontent" is among the changed 
elements. That works. Thanks for the hint.

I don't know if a 'loaded' event would make sense. Also, I suspect that it 
works for me because of the network latency of getting the SVG file, but there 
is no guarantee that the extensions are loaded before the file.

Original comment by mor...@wissenba.ch on 3 Apr 2012 at 2:27

GoogleCodeExporter commented 8 years ago
That's a valid concern, but I do believe svg-editor.js make use of .ready() to 
load from URL and extensions may run even before that. See the comments on 
svg-editor.js:4850
            // Note that we don't want this on Editor.ready since some extensions
            // may want to run before then (like server_opensave).

Original comment by asyazwan on 4 Apr 2012 at 5:31

GoogleCodeExporter commented 8 years ago
Looks like it. That renders this issue resolved as far as I'm concerned. Thanks 
for the help!

Original comment by mor...@wissenba.ch on 4 Apr 2012 at 11:30

GoogleCodeExporter commented 8 years ago

Original comment by asyazwan on 4 Apr 2012 at 1:39