Opened 13 years ago
Closed 9 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)
Change History (17)
Changed 13 years ago by
Attachment: | connect.patch added |
---|
comment:1 Changed 13 years ago by
comment:2 follow-up: 3 Changed 13 years ago by
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 follow-up: 4 Changed 13 years ago by
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 Changed 13 years ago by
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:6 Changed 13 years ago by
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 13 years ago by
Attachment: | connectv2.patch added |
---|
comment:7 Changed 13 years ago by
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 follow-up: 9 Changed 13 years ago by
Ok... in that case is there more than one handle in the array?
comment:9 Changed 13 years ago by
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 13 years ago by
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 13 years ago by
Summary: | Support for event suspend/resume → [patch][cla]Support for event suspend/resume |
---|
comment:12 Changed 13 years ago by
Milestone: | 1.2 → 1.3 |
---|
bump enhancements to next milestone, as we prepare to close out 1.2
comment:13 Changed 12 years ago by
Milestone: | 1.3 → future |
---|
This keeps getting bumped. Maybe for 2.0? People have reportedly been using this patch for a while now?
comment:15 Changed 9 years ago by
Milestone: | future → 1.7 |
---|---|
Resolution: | → fixed |
Status: | new → closed |
Although not based on this patch, this was implemented in 1.7 with on.pausable, see http://livedocs.dojotoolkit.org/dojo/on#pausable-function.
Added documentation with example for using suspend() and resume():