Search in sources :

Example 6 with JsPropertyMap

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);
    }
}
Also used : JsObject(elemental2.core.JsObject) JsPropertyMap(jsinterop.base.JsPropertyMap) JsOverlay(jsinterop.annotations.JsOverlay)

Example 7 with JsPropertyMap

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);
}
Also used : PropOptions(com.axellience.vuegwt.core.client.component.options.props.PropOptions) JsPropertyMap(jsinterop.base.JsPropertyMap) JsOverlay(jsinterop.annotations.JsOverlay)

Example 8 with JsPropertyMap

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);
}
Also used : JsPropertyMap(jsinterop.base.JsPropertyMap) JsOverlay(jsinterop.annotations.JsOverlay)

Example 9 with JsPropertyMap

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;
}
Also used : JsPropertyMap(jsinterop.base.JsPropertyMap)

Aggregations

JsPropertyMap (jsinterop.base.JsPropertyMap)9 JsObject (elemental2.core.JsObject)5 JsOverlay (jsinterop.annotations.JsOverlay)3 VueComponent (com.axellience.vuegwt.core.client.component.VueComponent)2 ComponentJavaPrototype (com.axellience.vuegwt.core.client.component.ComponentJavaPrototype)1 PropOptions (com.axellience.vuegwt.core.client.component.options.props.PropOptions)1 VueJsConstructor (com.axellience.vuegwt.core.client.vue.VueJsConstructor)1 Function (elemental2.core.Function)1 HashMap (java.util.HashMap)1 JsFunction (jsinterop.annotations.JsFunction)1