Opened 11 years ago

Closed 8 years ago

#6723 closed enhancement (fixed)

[patch][cla]Support for event suspend/resume

Reported by: Tom Trenka Owned by: dylan
Priority: high Milestone: 1.7
Component: Events Version: 1.1.0
Keywords: Cc:
Blocked By: Blocking:

Description

Add support to dojo.connect for suspending and resuming connections. Patch attached, original from Scott Miles.

Attachments (2)

connect.patch (3.3 KB) - added by Tom Trenka 11 years ago.
connectv2.patch (3.4 KB) - added by cb1kenobi 11 years ago.

Download all attachments as: .zip

Change History (17)

Changed 11 years ago by Tom Trenka

Attachment: connect.patch added

comment:1 Changed 11 years ago by Tom Trenka

Added documentation with example for using suspend() and resume():

var link=dojo.connect(obj, "foo", obj, "bar");
...
link.suspend();
...
link.resume();
...
dojo.disconnect(link);

comment:2 Changed 11 years ago by guest

From within a widget, you have to get the last handle:

var handles = this.connect(this.someNode, "onclick", function(evt){
    /* handler code goes here */
});
var link = handles[handles.length-1];
...
link.suspend();
...
link.resume();

-Chris Barber

comment:3 in reply to:  2 ; Changed 11 years ago by bill

Replying to guest:

From within a widget, you have to get the last handle:

Actually, if you do want to support this feature from _Widget.connect(), you need to suspend/resume every element in the handles array, not just the last one.

comment:4 in reply to:  3 Changed 11 years ago by cb1kenobi

Replying to bill:

Replying to guest:

From within a widget, you have to get the last handle:

Actually, if you do want to support this feature from _Widget.connect(), you need to suspend/resume every element in the handles array, not just the last one.

Why is that? I suspend/resume the last handle and my code works fine. I can destroy the widget and recreate it and there doesn't appear to be any issues.

comment:5 Changed 11 years ago by bill

Probably you didn't test keyboard.

comment:6 Changed 11 years ago by cb1kenobi

I've been using this patch in my project and I love this feature. There's one scenario I hit that caused an issue though.

var link=dojo.connect(obj, "foo", obj, "bar");
...
function foo(){
    link.suspend(); // already disconnected
    ...
    link.resume(); // re-connects the event
}
...
link.suspend(); // disconnects the event
...
foo();
...
link.resume(); // re-connects the event again
...
dojo.disconnect(link);

Now the event is attached twice and that's no good.

I've uploaded a v2 of this patch that includes a flag to keep track of the suspended state. This fixed my issues and life is good.

Changed 11 years ago by cb1kenobi

Attachment: connectv2.patch added

comment:7 in reply to:  5 Changed 11 years ago by cb1kenobi

Replying to bill:

Probably you didn't test keyboard.

I remember seeing that code, but this only is an issue if you _Widget.connect() to the "ondijitclick" event. In my case, I'm connecting to onchange of a select drop down and it works fine to grab the last handle.

comment:8 Changed 11 years ago by bill

Ok... in that case is there more than one handle in the array?

comment:9 in reply to:  8 Changed 11 years ago by cb1kenobi

Replying to bill:

Ok... in that case is there more than one handle in the array?

Sometimes yes, there is more than one handle, but it's not a big deal since I'm creating a local reference to the event like this:

postCreate: function(){
    var h = this.connect(this.myDropDown, "onchange", "_onChange");
    this._evt = h[h.length-1];
},
repopulateList: function(){
    this._evt.suspend();
    // code that clears and re-adds options to this.myDropDown goes here
    this._evt.resume();
}

comment:10 Changed 11 years ago by bill

OK, well what I'm saying is that you need to suspend/resume all handles in the array. In the case where there is only one handle in the array, you are free to just suspend just "the last one", but of course that ends up being exactly the same thing.

comment:11 Changed 11 years ago by Adam Peller

Summary: Support for event suspend/resume[patch][cla]Support for event suspend/resume

comment:12 Changed 11 years ago by bill

Milestone: 1.21.3

bump enhancements to next milestone, as we prepare to close out 1.2

comment:13 Changed 11 years ago by dante

Milestone: 1.3future

This keeps getting bumped. Maybe for 2.0? People have reportedly been using this patch for a while now?

comment:14 Changed 8 years ago by Chris Mitchell

Owner: changed from alex to dylan

please review/triage

comment:15 Changed 8 years ago by bill

Milestone: future1.7
Resolution: fixed
Status: newclosed

Although not based on this patch, this was implemented in 1.7 with on.pausable, see http://livedocs.dojotoolkit.org/dojo/on#pausable-function.

Note: See TracTickets for help on using tickets.