Revision: 10524
Author: bobv%google....@gtempaccount.com
Date: Mon Aug 15 07:40:18 2011
Log: Edited wiki page RequestFactory_2_4 through web user interface.
http://code.google.com/p/google-web-toolkit/source/detail?r=10524
Modified:
/wiki/RequestFactory_2_4.wiki
=======================================
--- /wiki/RequestFactory_2_4.wiki Sat Jun 11 17:16:56 2011
+++ /wiki/RequestFactory_2_4.wiki Mon Aug 15 07:40:18 2011
@@ -83,3 +83,32 @@
Any `RequestContext` may have another newly-created `RequestContext`
appended to it. Once two `RequestContext` instances are joined, they may
be used independently of one another until `fire()` is called on any of the
`RequestContext` instances.
Building on top of the `append()` facility is the utility class
`RequestBatcher` which makes it easy to combine all `Request`s made during
one tick of the event loop into a single HTTP request. A `RequestBatcher`
vends an instance of a `RequestContext` and automatically calls `fire()` on
it before the JavaScript execution returns to the browser (via
`Scheduler.scheduleFinally()`). The public `fire()` methods on the
returned `RequestContext` and its `Request` objects will not trigger an
HTTP request, although any `Receiver` provided will still be enqueued,
allowing the `RequestContext` vended by a `RequestBatcher` to be used with
existing code.
+
+{{{
+public class MyRequestBatcher extends RequestBatcher<MyRequestFactory,
MyRequestContext> {
+ // Could be provided to consumers via DI instead
+ public static final MyRequestBatcher INSTANCE = new MyRequestBatcher();
+
+ public MyRequestBatcher() {
+ // MyRequestFactory could also be injected
+ super(GWT.create(MyRequestFactory.class));
+ }
+
+ @Override
+ protected MyRequestContext createContext(MyRequestFactory factory) {
+ return factory.myRequestContext();
+ }
+
+ // Provide batched getter for an additional RequestContext type
+ public OtherRequestContext otherRequestContext() {
+ return get().append(getRequestFactory().otherRequestContext());
+ }
+}
+}}}
+{{{
+public void respondToUserAction() {
+ MyRequestContext ctx = MyRequestBatcher.INSTANCE.get();
+ ctx.doUsualThings();
+ // Calling fire() would be a no-op, although fire(Receiver<Void>) will
enqueue the callback
+}
+}}}
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors