mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 00:04:10 -08:00
jso: move interfaces from 'util.function' to 'function' subpackage, rename JSFunction
to JSMapping
to avoid name clash
This commit is contained in:
parent
a1d711d069
commit
81fc843da3
|
@ -22,9 +22,9 @@ import org.teavm.jso.JSFunctor;
|
|||
import org.teavm.jso.JSMethod;
|
||||
import org.teavm.jso.JSObject;
|
||||
import org.teavm.jso.JSProperty;
|
||||
import org.teavm.jso.util.function.JSConsumer;
|
||||
import org.teavm.jso.util.function.JSFunction;
|
||||
import org.teavm.jso.util.function.JSSupplier;
|
||||
import org.teavm.jso.function.JSConsumer;
|
||||
import org.teavm.jso.function.JSMapping;
|
||||
import org.teavm.jso.function.JSSupplier;
|
||||
|
||||
/**
|
||||
* Interface for interacting with JavaScript
|
||||
|
@ -76,29 +76,29 @@ public class JSPromise<T> implements JSObject {
|
|||
public static native <V> JSPromise<V> reject(Object reason);
|
||||
|
||||
/** Call {@code onFulfilled} with the success value, resolving with its return value. */
|
||||
public native <V> JSPromise<V> then(JSFunction<T, V> onFulfilled);
|
||||
public native <V> JSPromise<V> then(JSMapping<T, V> onFulfilled);
|
||||
|
||||
/** Call {@code onFulfilled} with the success value or {@code onRejected} with the reject reason,
|
||||
* resolving with its return value. */
|
||||
public native <V> JSPromise<V> then(JSFunction<T, V> onFulfilled, JSFunction<Object, V> onRejected);
|
||||
public native <V> JSPromise<V> then(JSMapping<T, V> onFulfilled, JSMapping<Object, V> onRejected);
|
||||
|
||||
/** Call {@code onFulfilled} with the success value, returning a new promise. */
|
||||
@JSMethod("then")
|
||||
public native <V> JSPromise<V> flatThen(JSFunction<T, ? extends JSPromise<V>> onFulfilled);
|
||||
public native <V> JSPromise<V> flatThen(JSMapping<T, ? extends JSPromise<V>> onFulfilled);
|
||||
|
||||
/** Call {@code onFulfilled} with the success value or {@code onRejected} with the reject reason,
|
||||
* returning a new promise. */
|
||||
@JSMethod("then")
|
||||
public native <V> JSPromise<V> flatThen(JSFunction<T, ? extends JSPromise<V>> onFulfilled,
|
||||
JSFunction<Object, ? extends JSPromise<V>> onRejected);
|
||||
public native <V> JSPromise<V> flatThen(JSMapping<T, ? extends JSPromise<V>> onFulfilled,
|
||||
JSMapping<Object, ? extends JSPromise<V>> onRejected);
|
||||
|
||||
/** Call {@code onRejected} with the reject reason, resolving with its return value. */
|
||||
@JSMethod("catch")
|
||||
public native <V> JSPromise<V> catchError(JSFunction<Object, V> onRejected);
|
||||
public native <V> JSPromise<V> catchError(JSMapping<Object, V> onRejected);
|
||||
|
||||
/** Call {@code onRejected} with the reject reason, returning a new promise. */
|
||||
@JSMethod("catch")
|
||||
public native <V> JSPromise<V> flatCatchError(JSFunction<Object, ? extends JSPromise<V>> onRejected);
|
||||
public native <V> JSPromise<V> flatCatchError(JSMapping<Object, ? extends JSPromise<V>> onRejected);
|
||||
|
||||
/** Call {@code onFinally} after settling, ignoring the return value. */
|
||||
@JSMethod("finally")
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2023 Bernd Busse.
|
||||
* Copyright 2024 Alexey Andreev.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.teavm.jso.util.function;
|
||||
package org.teavm.jso.function;
|
||||
|
||||
import java.util.Objects;
|
||||
import org.teavm.jso.JSFunctor;
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2023 Bernd Busse.
|
||||
* Copyright 2024 Alexey Andreev.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.teavm.jso.util.function;
|
||||
package org.teavm.jso.function;
|
||||
|
||||
import java.util.Objects;
|
||||
import org.teavm.jso.JSFunctor;
|
||||
|
@ -21,10 +21,10 @@ import org.teavm.jso.JSObject;
|
|||
|
||||
@FunctionalInterface
|
||||
@JSFunctor
|
||||
public interface JSFunction<T, R> extends JSObject {
|
||||
public interface JSMapping<T, R> extends JSObject {
|
||||
R apply(T t);
|
||||
|
||||
default <V> JSFunction<T, V> andThen(JSFunction<? super R, ? extends V> after) {
|
||||
default <V> JSMapping<T, V> andThen(JSMapping<? super R, ? extends V> after) {
|
||||
Objects.requireNonNull(after);
|
||||
|
||||
return (T t) -> {
|
||||
|
@ -33,7 +33,7 @@ public interface JSFunction<T, R> extends JSObject {
|
|||
};
|
||||
}
|
||||
|
||||
default <V> JSFunction<V, R> compose(JSFunction<? super V, ? extends T> before) {
|
||||
default <V> JSMapping<V, R> compose(JSMapping<? super V, ? extends T> before) {
|
||||
Objects.requireNonNull(before);
|
||||
|
||||
return (V v) -> {
|
||||
|
@ -42,7 +42,7 @@ public interface JSFunction<T, R> extends JSObject {
|
|||
};
|
||||
}
|
||||
|
||||
static <T> JSFunction<T, T> identity() {
|
||||
static <T> JSMapping<T, T> identity() {
|
||||
return (T t) -> {
|
||||
return t;
|
||||
};
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2023 Bernd Busse.
|
||||
* Copyright 2024 Alexey Andreev.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.teavm.jso.util.function;
|
||||
package org.teavm.jso.function;
|
||||
|
||||
import org.teavm.jso.JSFunctor;
|
||||
import org.teavm.jso.JSObject;
|
|
@ -21,9 +21,9 @@ import org.teavm.jso.browser.Window;
|
|||
import org.teavm.jso.core.JSArray;
|
||||
import org.teavm.jso.core.JSPromise;
|
||||
import org.teavm.jso.core.JSString;
|
||||
import org.teavm.jso.util.function.JSConsumer;
|
||||
import org.teavm.jso.util.function.JSFunction;
|
||||
import org.teavm.jso.util.function.JSSupplier;
|
||||
import org.teavm.jso.function.JSConsumer;
|
||||
import org.teavm.jso.function.JSMapping;
|
||||
import org.teavm.jso.function.JSSupplier;
|
||||
|
||||
public final class PromiseExample {
|
||||
private static long start = System.currentTimeMillis();
|
||||
|
@ -67,15 +67,15 @@ public final class PromiseExample {
|
|||
private static void checkFunctionalInterface() {
|
||||
JSSupplier<Integer> supplier = () -> 23;
|
||||
|
||||
JSFunction<Integer, Integer> addTwenty = value -> value + 20;
|
||||
JSFunction<Integer, Integer> subTwenty = value -> value - 20;
|
||||
JSFunction<Integer, Boolean> isPositive = value -> value >= 0;
|
||||
JSMapping<Integer, Integer> addTwenty = value -> value + 20;
|
||||
JSMapping<Integer, Integer> subTwenty = value -> value - 20;
|
||||
JSMapping<Integer, Boolean> isPositive = value -> value >= 0;
|
||||
|
||||
JSConsumer<Integer> print = value -> report("My value: " + value.toString());
|
||||
JSConsumer<Integer> print2 = value -> report("My value plus 10: " + Integer.valueOf(value + 10).toString());
|
||||
|
||||
var value = supplier.get();
|
||||
report("Supplied value: " + value.toString());
|
||||
report("Supplied value: " + value);
|
||||
|
||||
value = addTwenty.apply(value);
|
||||
report("Value plus 20: " + value.toString());
|
||||
|
@ -176,7 +176,7 @@ public final class PromiseExample {
|
|||
}
|
||||
|
||||
private static void runLongRunningPromise(Object lock) {
|
||||
var promise = new JSPromise<>((resolve, reject) -> {
|
||||
new JSPromise<>((resolve, reject) -> {
|
||||
report("Long promise exection");
|
||||
report("Wait for a while...");
|
||||
Window.setTimeout(() -> {
|
||||
|
@ -250,7 +250,7 @@ public final class PromiseExample {
|
|||
var item = value.get(i);
|
||||
var msg = "-- Promise " + i + " " + item.getStatus() + " with: ";
|
||||
if (item.getStatus().stringValue().equals("fulfilled")) {
|
||||
msg += item.getValue().toString();
|
||||
msg += item.getValue();
|
||||
} else if (item.getStatus().stringValue().equals("rejected")) {
|
||||
msg += item.getReason().toString();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user