use of jsinterop.base.JsPropertyMap in project vue-gwt by Axellience.
the class VueComponentOptions method initData.
/**
* Initialise the data structure, then set it to either a Factory or directly on the Component.
* @param useFactory Boolean representing whether or not to use a Factory.
* @param fieldNames Name of the data fields in the object
*/
@JsOverlay
public final void initData(boolean useFactory, String... fieldNames) {
dataFields = JsPropertyMap.of();
for (String fieldName : fieldNames) {
// Get the default field value from the prototype if any
Object defaultValue = componentJavaPrototype.get(fieldName);
if (!Js.isTripleEqual(defaultValue, Js.undefined()))
dataFields.set(fieldName, defaultValue);
else
dataFields.set(fieldName, null);
}
if (useFactory) {
String dataFieldsJSON = JSON.stringify(dataFields);
this.setData((DataFactory) () -> (JsPropertyMap) JSON.parse(dataFieldsJSON));
} else {
this.setData((DataFactory) () -> dataFields);
}
}
use of jsinterop.base.JsPropertyMap in project vue-gwt by Axellience.
the class VueComponentOptions method addJavaProp.
/**
* Add a prop to our ComponentOptions.
* This will allow to receive data from the outside of our Component.
* @param propName The name of the property
* @param required Is the property required (mandatory)
* @param jsTypeName JS name of the type of this property, if not null we will ask Vue to type
* check based on it
*/
@JsOverlay
public final void addJavaProp(String propName, boolean required, String jsTypeName) {
PropOptions propDefinition = new PropOptions();
propDefinition.required = required;
if (jsTypeName != null)
propDefinition.type = ((JsPropertyMap<Object>) DomGlobal.window).get(jsTypeName);
addProp(propName, propDefinition);
}
use of jsinterop.base.JsPropertyMap in project vue-gwt by Axellience.
the class VueComponentOptions method addJavaWatch.
/**
* Add a watch property to this Component Definition
* @param javaMethodName Name of the method in the {@link VueComponent}
* @param watchedPropertyName Name of the property name to watch in the data model
* @param isDeep Is the watcher deep (will watch child properties)
*/
@JsOverlay
public final void addJavaWatch(String javaMethodName, String watchedPropertyName, boolean isDeep) {
if (!isDeep) {
addWatch(watchedPropertyName, getJavaComponentMethod(javaMethodName));
return;
}
JsPropertyMap watchDefinition = JsPropertyMap.of();
watchDefinition.set("deep", true);
watchDefinition.set("handler", getJavaComponentMethod(javaMethodName));
addWatch(watchedPropertyName, watchDefinition);
}
use of jsinterop.base.JsPropertyMap in project vue-gwt by Axellience.
the class VueGWTTools method getDeepValue.
/**
* Return a "deep" value in a given object by following an expression in the
* form: "parent.child.property". This only works if all the chain is
* exposed using JsInterop.
* @param object The root object to get on
* @param path The path to follow
* @param <T> The type of object we get in return
* @return The object at the end of the chain
*/
public static <T> T getDeepValue(Object object, String path) {
JsPropertyMap objectMap = (JsPropertyMap) object;
String[] pathSplit = path.split("\\.");
for (String s : pathSplit) {
objectMap = (JsPropertyMap) objectMap.get(s);
}
return (T) objectMap;
}
Aggregations