[Checkins] SVN: z3c.formjs/trunk/src/z3c/formjs/jsaction. Make sure
duplicate subscriptions are not created after multiple widget
updates.
Paul Carduner
paulcarduner at gmail.com
Thu Jun 26 12:30:03 EDT 2008
Log message for revision 87805:
Make sure duplicate subscriptions are not created after multiple widget updates.
Changed:
U z3c.formjs/trunk/src/z3c/formjs/jsaction.py
U z3c.formjs/trunk/src/z3c/formjs/jsaction.txt
-=-
Modified: z3c.formjs/trunk/src/z3c/formjs/jsaction.py
===================================================================
--- z3c.formjs/trunk/src/z3c/formjs/jsaction.py 2008-06-26 15:25:23 UTC (rev 87804)
+++ z3c.formjs/trunk/src/z3c/formjs/jsaction.py 2008-06-26 16:30:00 UTC (rev 87805)
@@ -193,6 +193,11 @@
# We only have work to do, if there are JS Handlers in the form.
if not hasattr(widget.form, 'jshandlers'):
return
+ # Only handle this event if we haven't already done so.
+ if getattr(widget, '__z3c_formjs_subscriptions_created__', None) is True:
+ return
+ widget.__z3c_formjs_subscriptions_created__ = True
+
# Step 1: Get the handler.
handlers = widget.form.jshandlers.getHandlers(widget.field)
# Step 2: Create a selector.
Modified: z3c.formjs/trunk/src/z3c/formjs/jsaction.txt
===================================================================
--- z3c.formjs/trunk/src/z3c/formjs/jsaction.txt 2008-06-26 15:25:23 UTC (rev 87804)
+++ z3c.formjs/trunk/src/z3c/formjs/jsaction.txt 2008-06-26 16:30:00 UTC (rev 87805)
@@ -743,11 +743,22 @@
>>> interfaces.IHaveJSSubscriptions.providedBy(form)
True
+ >>> len(list(form.jsSubscriptions))
+ 1
>>> list(form.jsSubscriptions)
[<JSSubscription
event=<JSEvent "click">, selector=<WidgetSelector "hello">,
handler=<JSHandler <function showHelloWorldMessage at ...>>>]
+In the event that the widget is updated multiple times, and the
+subscriber gets called multiple times, duplicate subscriptions will
+not be created.
+
+ >>> jsaction.createSubscriptionsForWidget(
+ ... widget.AfterWidgetUpdateEvent(helloWidget))
+ >>> len(list(form.jsSubscriptions))
+ 1
+
Finally, if the form does not have any Javascript handlers, in other words, it
does not have a ``jsHandlers`` attribute, then the subscriber also aborts:
More information about the Checkins
mailing list