UInterface ScriptΒΆ

The UInterface script is kind of an interface to the UFile data, or can be used that way anyhow. The script can access the ufile values, and whatever the script returns replaces the user’s value in the Module JS and Module HTML contexts.

// pseudo uinterface script 
module.exports = {
 load: function(myval, collection) {
  js.username
  js.jslib.<alias>
  // can return anything
  }
 save: function(newval)            {// can return anything}
 serialize: function(myval)        {// must return string!}
 deserialize: function(string)     {// can return anything}
}

If the serialize and deserialize methods are not over-written above, the following defaults are used:

export function defaultSerialize(val){
  if(_.isString(val)){
    return val
  }
  return JSON.stringify(val)
}
export function defaultDeserialize(str_val){
  assert(_.isString(str_val), "input value to deserialize must be a string")
  try{
    return JSON.parse(str_val)
  }catch(e){
    return str_val
  }
}