kerusan / Cup

Cappuccino UI and controller for jQuery File Upload
http://blueimp.github.io/jQuery-File-Upload/
1 stars 0 forks source link

The Cup object is not reentrant #1

Open kerusan opened 11 years ago

kerusan commented 11 years ago

If having 2 Cup objects in the application with different outlets to arrayControllers etc. the outlet of the first one is overriding the second.

kerusan commented 11 years ago

Since the Cup object is not a singleton it should be possible to allocate it in more than one instance. Right now this does not work because of the file variable 'callbacks'. This variable is set once with the callback functions the jQuery.fileUpload script uses to message the Cup object. The method 'setCallbacks:' is implemented to set the variable once and if called a second time it is not creating new functions but is setting the options with those functions that where set the first time, This effectively hinders the Cup object to function in more than one instance since the functions contains messages sent to 'self'. The 'self' object is copied into the function and therefore all callbacks will use the first allocated object as 'self'. So all instances of Cup will call the first allocated Cup object when called back. See:

    callbacks =
    {
        add: function(e, data)
        {
            currentEvent = e;
            currentData = data;
            [self addFile:data.files[0]];
            [self pumpRunLoop];
        },

......

Here ' [self addFile:data.files[0]];' will be sent to the first instance allocated from the Cup class.

By making the callbacks variable local to the method and removing the test if not nil it will probably be fixed.