use of jsinterop.base.JsPropertyMap in project vue-gwt by Axellience.
the class VueGwtExamplesService method addExample.
private static void addExample(String exampleId, VueFactory exampleVueFactory) {
// If we find the containing div for this example, we instantiate it
if (DomGlobal.document.getElementById(exampleId) != null) {
VueComponent exampleInstance = Vue.attach("#" + exampleId, exampleVueFactory);
((JsPropertyMap) DomGlobal.window).set(exampleId, exampleInstance);
}
}
use of jsinterop.base.JsPropertyMap 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);
}
use of jsinterop.base.JsPropertyMap 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));
});
}
use of jsinterop.base.JsPropertyMap in project vue-gwt by Axellience.
the class VueGWTObserverManager method initClassPropertiesCache.
private Map<String, Object> initClassPropertiesCache(JsObject object, String className) {
final Map<String, Object> tmpCache = new HashMap<>();
classesPropertyCaches.put(className, tmpCache);
JsPropertyMap prototype = (JsPropertyMap) object.__proto__;
prototype.forEach(property -> {
Object value = prototype.get(property);
if (isDefaultValue(value)) {
tmpCache.put(property, value);
}
});
return tmpCache;
}
use of jsinterop.base.JsPropertyMap in project vue-gwt by Axellience.
the class VueGWTObserverManager method makeStaticallyInitializedPropertiesReactive.
/**
* Due to GWT optimizations, properties on java object defined like this are not observable in
* Vue.js when not running in dev mode:
* <br>
* private String myText = "Default text";
* private int myInt = 0;
* <br>
* This is because GWT define the default value on the prototype and don't define it on the
* object.
* Therefore Vue.js don't see those properties when initializing it's observer.
* To fix the issue, we manually look for those properties and set them explicitly on the
* object.
* @param object The Java object to observe
* @param className The Java class name to observe
*/
private void makeStaticallyInitializedPropertiesReactive(JsObject object, String className) {
Map<String, Object> cache = classesPropertyCaches.get(className);
if (cache == null) {
cache = initClassPropertiesCache(object, className);
}
JsPropertyMap javaObjectPropertyMap = ((JsPropertyMap) object);
cache.forEach((key, value) -> {
if (!object.hasOwnProperty(key))
javaObjectPropertyMap.set(key, value);
});
}
Aggregations