Hi,
thanks for sharing this!
I've checked the original photoshopDelegate (the one in the Adobe's panel) and I'm not sure what the event.delegate is (line 65..75)
PhotoshopDelegate.prototype.addEvents = function(event) { /* if(!_.isArray(events)) { events = [events]; } */ csInterface.evalScript( "app.stringIDToTypeID('"+ event.name + "');", function(result) { this._eventMap[+result] = event.delegate; this._registerEvent(); }.bind(this) ); };
It looks like they use addEvents passing an array of event objects in which the event.name is the typeID and the event.delegate is the callback - am I right?
---
UPDATE
Besides,
I've seen your removeEventListener, which I append below as a handy reference:
EventDelegate.prototype.removeEventListener = function( typeStrings, callback ) { csInterface.evalScript( "s2t('"+typeStrings+"')", function(r){ this._events[+r.split(',')[0]] = null; }.bind(this) ); }
I have a couple of questions for you, if I may ask:
1. Is there a reason not to include a this.__registerPSEvent( r, true ); in there too? Basically in your code when the removeEventListener is called, the com.adobe.photoshopUnRegisterEvent is not actually dispatched - it's just removed the callback in the this._events array. So you don't remove the listener, just set the callback as null.
2. It looks like your s2t accepts / returns an array, since the param is typeStrings (plural) and you r.split(',')[0] - but you hardwire the first returned value so I guess you plan to use removeEventListener for a single event - am I correct?
---
Thank you,
Davide Barranca
---
www.davidebarranca.com
www.cs-extensions.com