Search in sources :

Example 1 with Function

use of elemental2.core.Function in project vue-gwt by Axellience.

the class VueGWTObserverManager method captureVueObserver.

/**
 * Capture the Vue Observer by creating a Vue Instance on the fly
 */
private void captureVueObserver() {
    HTMLScriptElement scriptElement = (HTMLScriptElement) DomGlobal.document.createElement("script");
    scriptElement.text = "new Vue({created: function () {VueGWT.VueGWTObserverManager.get().customizeVueObserverPrototype(this.$data.__ob__.__proto__);}});";
    DomGlobal.document.body.appendChild(scriptElement);
}
Also used : HTMLScriptElement(elemental2.dom.HTMLScriptElement)

Example 2 with Function

use of elemental2.core.Function in project vue-gwt by Axellience.

the class VueGWTTools method wrapMethod.

/**
 * Proxy a method call to be warned when it called. This requires the
 * function to be JsInterop (name shouldn't change at runtime). This used to
 * observe Java Collections/Map. It won't be necessary in future versions of
 * Vue.js based on ES6 proxies.
 * @param object The object to observe
 * @param methodName The name of the method to proxify
 * @param afterMethodCall A callback called each time after the method has
 * been executed
 * @param <T> Type of the object the we Proxy
 */
public static <T> void wrapMethod(T object, String methodName, AfterMethodCall<T> afterMethodCall) {
    Function method = (Function) ((JsPropertyMap) object).get(methodName);
    WrappingFunction wrappingFunction = args -> {
        Object result = method.apply(object, args);
        afterMethodCall.execute(object, methodName, result, args);
        return result;
    };
    ((JsPropertyMap) object).set(methodName, wrappingFunction);
}
Also used : JsFunction(jsinterop.annotations.JsFunction) VueJsConstructor(com.axellience.vuegwt.core.client.vue.VueJsConstructor) Function(elemental2.core.Function) VueComponent(com.axellience.vuegwt.core.client.component.VueComponent) JsPropertyMap(jsinterop.base.JsPropertyMap) ComponentJavaPrototype(com.axellience.vuegwt.core.client.component.ComponentJavaPrototype) JsObject(elemental2.core.JsObject) JsFunction(jsinterop.annotations.JsFunction) Function(elemental2.core.Function) JsObject(elemental2.core.JsObject) JsPropertyMap(jsinterop.base.JsPropertyMap)

Example 3 with Function

use of elemental2.core.Function in project vue-gwt by Axellience.

the class VueGWTTools method extendVueConstructorWithJavaPrototype.

/**
 * Copy a Java class prototype to a VueComponent declaration. This allows
 * VueComponent created by Vue to pass as an instance of the VueComponent
 * class they implement.
 * @param extendedVueJsConstructor The Vue.js constructor function to extend
 * @param componentJavaPrototype The VueComponent class JS prototype to
 * extend with
 * @param <T> The type of the VueComponent
 */
public static <T extends VueComponent> void extendVueConstructorWithJavaPrototype(VueJsConstructor<T> extendedVueJsConstructor, ComponentJavaPrototype<T> componentJavaPrototype) {
    JsPropertyMap vueProto = (JsPropertyMap) ((JsPropertyMap) extendedVueJsConstructor).get("prototype");
    JsObject vueProtoJsObject = ((JsObject) vueProto);
    componentJavaPrototype.forEach(protoProp -> {
        if (!vueProtoJsObject.hasOwnProperty(protoProp))
            vueProto.set(protoProp, componentJavaPrototype.get(protoProp));
    });
}
Also used : JsObject(elemental2.core.JsObject) JsPropertyMap(jsinterop.base.JsPropertyMap)

Example 4 with Function

use of elemental2.core.Function in project kie-wb-common by kiegroup.

the class DNDListComponentView method getNextElement.

private Element getNextElement(final Element element, final Function<HTMLElement, Boolean> function) {
    final int nextElementPosition = Position.getY(element) + 1;
    final HTMLElement next = querySelector(getDragArea()).getDraggableElement(nextElementPosition).orElse(null);
    if (function.apply(next) || next == null) {
        return next;
    }
    return getNextElement(next, function);
}
Also used : HTMLElement(elemental2.dom.HTMLElement)

Example 5 with Function

use of elemental2.core.Function in project kie-wb-common by kiegroup.

the class PromisesMock method promisify.

@SuppressWarnings("unchecked")
public static Promises promisify(final Promises promises) {
    doAnswer(invocationOnMock -> {
        final Caller caller = (Caller) invocationOnMock.getArguments()[0];
        final Function call = (Function) invocationOnMock.getArguments()[1];
        final Promise<Object>[] promise = new Promise[1];
        final Object service = caller.call(response -> promise[0] = PromiseMock.success(response));
        call.apply(service);
        return promise[0];
    }).when(promises).promisify(any(Caller.class), any(Function.class));
    return promises;
}
Also used : Function(java.util.function.Function) Promise(elemental2.promise.Promise) Caller(org.jboss.errai.common.client.api.Caller)

Aggregations

Function (elemental2.core.Function)3 JsObject (elemental2.core.JsObject)2 JsString (elemental2.core.JsString)2 HTMLOptionElement (elemental2.dom.HTMLOptionElement)2 JsPropertyMap (jsinterop.base.JsPropertyMap)2 ComponentJavaPrototype (com.axellience.vuegwt.core.client.component.ComponentJavaPrototype)1 VueComponent (com.axellience.vuegwt.core.client.component.VueComponent)1 VueJsConstructor (com.axellience.vuegwt.core.client.vue.VueJsConstructor)1 JsRegExp (elemental2.core.JsRegExp)1 HTMLElement (elemental2.dom.HTMLElement)1 HTMLOptGroupElement (elemental2.dom.HTMLOptGroupElement)1 HTMLScriptElement (elemental2.dom.HTMLScriptElement)1 Promise (elemental2.promise.Promise)1 Function (java.util.function.Function)1 JsFunction (jsinterop.annotations.JsFunction)1 JsOverlay (jsinterop.annotations.JsOverlay)1 Caller (org.jboss.errai.common.client.api.Caller)1