Foundations

Foundations is a loadable framework of utility JavaScript APIs that both Mojo and JavaScript service applications can use.

Component Description
Array Utilities Array operation calls. Right now, just one for clearing an array.
Assert Utilities Assert operation calls. Two versions are provided for each call: one that logs an error and one that throws an error.
Communication Utilities Wrappers for async Ajax calls and a Palm bus service call.
Control Utilities Utilities to implement asynchronous callbacks (Futures), finite state machines, and map reduce functionality.
Environment Utilities Run-time environment (runtime, browser, node) detection calls.
Object Utilities Object operation calls. Right now, just one for converting an object containing name/value pairs to a string.
String Utilities String operation calls -- converting, escaping, searching, and stripping (HTML).
Structure Utilities Wrapper for allocating error and class objects.

Using Foundations

To include Foundations in your Mojo app code:

  • Include the following two script tags in your app's "index.html" file:

    <script src="/usr/palm/frameworks/mojo/mojo.js" type="text/javascript"
      x-mojo-version="1"></script>
    <script src="/usr/palm/frameworks/mojoloader.js" type="text/javascript"></script>
    
    
  • Load the Foundations library and create short-hand references (optional) in your JavaScript:

    var libraries   = MojoLoader.require({ name: "foundations", version: "1.0" });
    var ArrayUtils  = libraries["foundations"].ArrayUtils;
    var AssertUtils = libraries["foundations"].Assert;  
    var EnvUtils    = libraries["foundations"].EnvironmentUtils; 
    var PalmCall    = libraries["foundations"].Comms.PalmCall; 
    var AjaxCall    = libraries["foundations"].Comms.AjaxCall; 
    var ObjUtils    = libraries["foundations"].ObjectUtils;
    var StringUtils = libraries["foundations"].StringUtils; 
    var Err         = libraries["foundations"].Err; 
    var Class       = libraries["foundations"].Class;  
    var DB          = libraries["foundations"].Data.DB;  // db8 JavaScript wrapper calls
    var Future      = libraries["foundations"].Control.Future;
    var FSM         = libraries["foundations"].Control.FSM;   
    var MapReduce   = libraries["foundations"].Control.mapReduce;    
    
    

To include Foundations in your service app code:

  • Import the Foundations library and create short-hand references (optional) in your JavaScript:

    var Foundations = IMPORTS.foundations;
    var ArrayUtils  = Foundations.ArrayUtils;
    var AssertUtils = Foundations.Assert;
    var EnvUtils    = Foundations.EnvironmentUtils;
    var PalmCall    = Foundations.Comms.PalmCall;
    var AjaxCall    = Foundations.Comms.AjaxCall;
    var ObjUtils    = Foundations.ObjectUtils;
    var StringUtils = Foundations.StringUtils;
    var Err         = Foundations.Err;
    var Class       = Foundations.Class;
    var DB          = Foundations.Data.DB;
    var Future      = Foundations.Control.Future;
    var FSM         = Foundations.Control.FSM;
    var MapReduce   = Foundations.Control.mapReduce;
    
    

    You can then reference methods using standard dot notation. For example: StringUtils.isBlank.