use of elemental2.core.JsObject 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 elemental2.core.JsObject 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 elemental2.core.JsObject 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