private boolean run(Object c, Object...o) {
// Unbox array inside array when there is only an element.
// It happens when running filters in Promise.then()
- if (o.length == 1 && o[0].getClass().isArray()) {
+ if (o != null && o.length == 1 && o[0] != null && o[0].getClass().isArray()) {
o = (Object[])o[0];
}
if (c instanceof Callback) {
// run the function with the new args to resolve this deferred
doIt.f();
}
- }
+ }
protected com.google.gwt.query.client.plugins.deferred.Deferred dfd;
+ /**
+ * Utility function which can be used inside classes extending this to
+ * resolve this deferred in a call to any other promise method.
+ *
+ * Example:
+ * <pre>
+ * new PromiseFunction() {
+ * public void f(final Deferred dfd) {
+ * anotherPromise.done( resolve );
+ * }
+ * }
+ * </pre>
+ */
+ protected Function resolve = new Function() {
+ public void f() {
+ dfd.resolve(arguments);
+ };
+ };
+
+ /**
+ * Utility function which can be used inside classes extending this to
+ * reject this deferred in a call to any other promise method.
+ *
+ * Example:
+ * <pre>
+ * new PromiseFunction() {
+ * public void f(final Deferred dfd) {
+ * anotherPromise.done( reject );
+ * }
+ * }
+ * </pre>
+ */
+ protected Function reject = new Function() {
+ public void f() {
+ dfd.reject(arguments);
+ };
+ };
+
protected DeferredPromiseImpl() {
dfd = new com.google.gwt.query.client.plugins.deferred.Deferred();
}