本文整理汇总了Java中com.google.gwt.query.client.Function类的典型用法代码示例。如果您正苦于以下问题:Java Function类的具体用法?Java Function怎么用?Java Function使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Function类属于com.google.gwt.query.client包,在下文中一共展示了Function类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadScript
import com.google.gwt.query.client.Function; //导入依赖的package包/类
public static Promise<Void, Exception> loadScript(String url, String... properties) {
return new Promise<>((resolve, reject) -> {
if (exists(properties)) {
resolve.e(null);
} else {
Ajax.loadScript(url).done(new Function() {
@Override
public void f() {
resolve.e(null);
}
}).fail(new Function() {
@Override
public void f() {
reject.e(new Exception(url + " not loaded"));
}
});
}
});
}
示例2: imports
import com.google.gwt.query.client.Function; //导入依赖的package包/类
public static Promise imports(String... urls) {
return new Promise<>((resolve, reject) -> GQuery.when(Arrays.stream(urls)
.map(url -> url.endsWith(".js") ? Ajax.loadScript(url) : Ajax.importHtml(url))
.toArray())
.done(new Function() {
@Override
public void f() {
resolve.e(getArguments());
}
})
.fail(new Function() {
@Override
public void f() {
reject.e(getArguments());
}
}));
}
示例3: googleMapsApiPromise
import com.google.gwt.query.client.Function; //导入依赖的package包/类
@JsOverlay
public static Promise googleMapsApiPromise() {
return new PromiseFunction() {
@Override
public void f(final Deferred deferred) {
if ($("google-maps-api").isEmpty()) {
$(body).append("<google-maps-api></google-maps-api>");
}
GQuery gMapsApi = $("google-maps-api");
if (gMapsApi.prop("libraryLoaded", Boolean.class)) {
deferred.resolve();
} else {
gMapsApi.on("api-load", new Function() {
@Override
public void f() {
deferred.resolve();
}
});
}
}
};
}
示例4: undelegate
import com.google.gwt.query.client.Function; //导入依赖的package包/类
public View undelegate(String eventName, String selector, Function listener) {
if(eventName == null) {
undelegateEvents();
} else {
eventName += ".delegateEvents" + this.cid;
if(selector != null && !selector.isEmpty()) {
this.$el.undelegate(selector, eventName);
} else if(listener != null) {
this.$el.unbind(eventName, listener);
} else {
ViewEventEntry viewEventEntry = delegatedEvents.get(eventName);
this.$el.undelegate(viewEventEntry.selector, eventName);
this.$el.unbind(eventName);
}
delegatedEvents.remove(eventName);
}
return this;
}
示例5: testNestedSetMultipleTimes
import com.google.gwt.query.client.Function; //导入依赖的package包/类
public void testNestedSetMultipleTimes() {
final int[] count = {0};
final Model model = new Model();
model.on("change:b", new Function() {
@Override
public void f() {
count[0]++;
}
});
model.on("change:a", new Function() {
@Override
public void f() {
model.set(O("b", true));
model.set(O("b", true));
}
});
model.set(O("a", true));
assertEquals(1, count[0]);
}
示例6: testFinalChangeEventIsAlwaysFiredRegardlessOfInterimChanges
import com.google.gwt.query.client.Function; //导入依赖的package包/类
public void testFinalChangeEventIsAlwaysFiredRegardlessOfInterimChanges() {
final int[] count = {0};
final Model model = new Model();
model.on("change:property", new Function() {
@Override
public void f() {
model.set("property", "bar");
}
});
model.on("change", new Function() {
@Override
public void f() {
count[0]++;
}
});
model.set("property", "foo");
assertEquals(1, count[0]);
}
示例7: testTriggerRouteEventOnRouterInstance
import com.google.gwt.query.client.Function; //导入依赖的package包/类
public void testTriggerRouteEventOnRouterInstance() {
final int[] counter = {0};
router.on("route", new Function() {
@Override
public void f() {
String name = getArgument(0);
String[] args = getArgument(1);
assertEquals("routeEvent", name);
assertEquals(Arrays.asList("x"), Arrays.asList(args));
counter[0]++;
}
});
location.replace("http://example.com#route-event/x");
History.get().checkUrl();
assertEquals(1, counter[0]);
}
示例8: testBindTwoCallbacksUnbindOnlyOne
import com.google.gwt.query.client.Function; //导入依赖的package包/类
public void testBindTwoCallbacksUnbindOnlyOne() {
final int[] counterA = {0};
final int[] counterB = {0};
Events obj = new Events();
Function callback = new Function() {
@Override
public void f() {
counterA[0]++;
}
};
obj.on("event", callback);
obj.on("event", new Function() {
@Override
public void f() {
counterB[0]++;
}
});
obj.trigger("event");
obj.off("event", callback);
obj.trigger("event");
assertEquals("counterA should have only been incremented once.", 1, counterA[0]);
assertEquals("counterB should have been incremented twice.", 2, counterB[0]);
}
示例9: testRemoveAllEventsForASpecificContext
import com.google.gwt.query.client.Function; //导入依赖的package包/类
public void testRemoveAllEventsForASpecificContext() {
final int[] counter = {0};
final Events obj = new Events();
final Function incr = new Function() {
@Override
public void f() {
counter[0]++;
}
};
obj.on("x y all", incr);
obj.on("x y all", incr, obj);
obj.off(null, null, obj);
obj.trigger("x y");
assertEquals(4, counter[0]);
}
示例10: once
import com.google.gwt.query.client.Function; //导入依赖的package包/类
public T once(final String name, final Function callback, Object context) {
if(callback == null) return (T)this;
if(eventsSplitter.test(name)) {
String[] names = name.split(eventsSplitter.getSource());
for (String splittedName : names) {
once(splittedName, callback, context);
}
} else {
final OnceFunction onceCallback = new OnceFunction(name, callback) {
@Override
public void once() {
off(getName(), this);
getCallback().f(getArguments());
}
};
on(name, onceCallback, context);
}
return (T)this;
}
示例11: testMultipleNestedChangesWithSilent
import com.google.gwt.query.client.Function; //导入依赖的package包/类
public void testMultipleNestedChangesWithSilent() {
final int[] count = {0};
final Model model = new Model();
model.on("change:x", new Function() {
@Override
public void f() {
model.set(O("y", 1), O("silent", true));
model.set(O("y", 2));
}
});
model.on("change:y", new Function() {
@Override
public void f() {
int value = getArgument(1);
assertEquals(2, value);
count[0]++;
}
});
model.set(O("x", true));
assertEquals(1, count[0]);
}
示例12: testAllCallbackListIsRetrievedAfterEachEvent
import com.google.gwt.query.client.Function; //导入依赖的package包/类
public void testAllCallbackListIsRetrievedAfterEachEvent() {
final int[] counter = {0};
final Events obj = new Events();
final Function incr = new Function() {
@Override
public void f() {
counter[0]++;
}
};
obj.on("x", new Function() {
@Override
public void f() {
obj.on("y", incr).on("all", incr);
}
}).trigger("x y");
assertEquals(2, counter[0]);
}
示例13: testListenToOnceAndStopListening
import com.google.gwt.query.client.Function; //导入依赖的package包/类
public void testListenToOnceAndStopListening() {
final int[] counter = {0};
Events a = new Events();
Events b = new Events();
final Function cb = new Function() {
@Override
public void f() {
counter[0]++;
}
};
a.listenToOnce(b, "all", cb);
b.trigger("anything");
b.trigger("anything");
a.listenToOnce(b, "all", cb);
a.stopListening();
b.trigger("anything");
assertEquals(1, counter[0]);
}
示例14: listenToOnce
import com.google.gwt.query.client.Function; //导入依赖的package包/类
public T listenToOnce(final Events obj, String name, Function callback) {
if(callback == null) return (T)this;
if(eventsSplitter.test(name)) {
String[] names = name.split(eventsSplitter.getSource());
for (String splittedName : names) {
listenToOnce(obj, splittedName, callback);
}
} else {
final OnceFunction onceCallback = new OnceFunction(name, callback) {
@Override
public void once() {
stopListening(obj, getName(), this);
getCallback().f(getArguments());
}
};
listenTo(obj, name, onceCallback);
}
return (T)this;
}
示例15: testNestedChangeAttrWithSilent
import com.google.gwt.query.client.Function; //导入依赖的package包/类
public void testNestedChangeAttrWithSilent() {
final int[] count = {0};
final Model model = new Model();
model.on("change:y", new Function() {
@Override
public void f() {
count[0]++;
}
});
model.on("change", new Function() {
@Override
public void f() {
model.set(O("y", true), O("silent", true));
model.set(O("z", true));
}
});
model.set(O("x", true));
assertEquals(0, count[0]);
}