Module: obitech-framework/jsx

obitech-framework/jsx

Classes

ArgumentError

Array

Callback

CallbackChain

CallbackCustom

Map

OBIActionError

OBIError

Methods

<static> Array.clone(arrayToClone, bFullClone) → {Array.<T>}

This method clones an array.
Parameters:
Name Type Description
arrayToClone Array.<T> The array you want to clone.
bFullClone Boolean A variable that controls whether the method clones the content 'arrayToClone' references. Default: false.
Returns:
Type
Array.<T>

<static> Array.remove(array, obj) → {T[]}

This static method enables you to remove an object from an array.
Parameters:
Name Type Description
array Array.<T> The array you want to remove the object from.
obj T the object you want to remove.
Returns:
An array with the removed object or empty if it wasn't in the array
Type
T[]

<static> assertArray(obj, name)

Assert that the argument is an array; else throw an Error.
Parameters:
Name Type Description
obj Array the object to test
name String the name of the function argument being tested

<static> assertArrayOf(obj, base, name, baseName)

Asserts that the argument is an array, and that each item in the array is of the type specified; else throws an error
Parameters:
Name Type Description
obj Array the array to test
base String | Function the typeof string or a base class function
name String the name of the object being tested
baseName String the name of the base class function

<static> assertArrayOf(obj, Array, name, Array)

Asserts that the argument is an array, and that each item in the array is one of the type specified; else throws an error.
Parameters:
Name Type Description
obj Array the array to test
Array Array.<(String|Function)> of typeof string or a base class function
name String the name of the object being tested
Array Array.<String> of the base class function names

<static> assertArrayOf(obj, base, name, baseName)

If not null, asserts that the argument is an array, and that each item in the array is one of the type specified; else throws an error.
Parameters:
Name Type Description
obj Array the array to test
base String | Function the typeof string or a base class function
name String the name of the object being tested
baseName String the name of the base class function

<static> assertArrayOfNumbers(obj, name)

Assert that the argument is an array and that each element in it is a number; else throw an error
Parameters:
Name Type Description
obj Array the object to test
name String the name of the object

<static> assertArrayOfStrings(obj, name)

Assert that the argument is an array and that each element in it is a string; else throw an error
Parameters:
Name Type Description
obj Array the object to test
name String the name of the object

<static> assertBoolean(obj, name)

Assert that the argument is a boolean; else throw an Error.
Parameters:
Name Type Description
obj Object the object to test
name String the name of the function argument being tested

<static> assertElement(obj, name)

Assert that the argument is a DOM element; else throw an Error.
Parameters:
Name Type Description
obj Object the object to test
name String the name of the function argument being tested

<static> assertEquals(obj, value, name)

Assert that the argument (strictly) equals the specified value
Parameters:
Name Type Description
obj Object the actual object to test
value Object the expected value of the object to test against
name String the name of the function argument being tested

<static> assertFilterReturnsTrue(obj, the, the)

Assert that the specified function return true; else throw an Error
Parameters:
Name Type Description
obj Object the object to pass to the filter function &@param {String} name the name of the object
the Function filter function
the String name of the filter

<static> assertFunction(obj, name)

Assert that the argument is a function; else throw an Error.
Parameters:
Name Type Description
obj Function the object to test
name String the name of the function argument being tested

<static> assertInstanceOf(obj, base, name, baseName)

Parameters:
Name Type Description
obj Object the object to test
base Function a base class
name String the name of the function argument being tested
baseName String the name of the base class

<static> assertInstanceOfModule(obj, sName, sBaseModule, sBaseClass)

Parameters:
Name Type Description
obj Object the object to test
sName String the name of the object being tested (for debugging). Required.
sBaseModule String the module path. Required.
sBaseClass String the name of the base class. Required.

<static> assertInstanceOfModule(obj, sName, sBaseModule, sBaseClass)

Parameters:
Name Type Description
obj Object the object to test
sName String the name of the object being tested (for debugging). Required.
sBaseModule String the module path. Required.
sBaseClass String the name of the base class. Required.

<static> assertInteger(obj, name)

Assert that the argument is a number that is an int; else throw an Error.
Parameters:
Name Type Description
obj Number the object to test
name String the name of the function argument being tested

<static> assertInteger(obj, name)

Assert that if the argument is not null, it is a number that is an int; else throw an Error.
Parameters:
Name Type Description
obj Number the object to test
name String the name of the function argument being tested

<static> assertJQueryElement($element, sName)

Assert that the argument is a JQuery object containing an element; else throw an error.
Parameters:
Name Type Description
$element jquery the jquery element to test
sName String the name of the object being tested

<static> assertJQueryElements($elements, sName, nOptionalExpectedNumElements)

Assert that the argument is a JQuery object containing one or more elements; else throw an error.
Parameters:
Name Type Description
$elements jquery the jquery element to test
sName String the name of the object being tested
nOptionalExpectedNumElements integer the optional expected number of elements. If not specified the function validates that there is at least one element.

<static> assertJQueryEvent($event, sName)

Assert that the argument is a JQuery event; else throw an error.
Parameters:
Name Type Description
$event JQuery.Event The jquery event to test
sName String The name of the object being tested

<static> assertNonEmptyArray(obj, name)

Assert that the argument object is a non-empty array; else throw an Error.
Parameters:
Name Type Description
obj Object the object to test
name String the name of the function argument being tested

<static> assertNonEmptyString(obj, name)

Assert that the argument is a string and not empty, else throw an Error.
Parameters:
Name Type Description
obj String the object to test
name String the name of the function argument being tested

<static> assertNoReferenceCycles(oObject, sName, aReferencesAlongPath)

Parameters:
Name Type Argument Description
oObject Object
the object to test for any cyclic references
sName String
the name of the object being tested
aReferencesAlongPath Array <optional>
references that should not be seen in the object else, we have detected a cycle

<static> assertNotNull(obj, name)

Assert that the argument is a function; else throw an Error.
Parameters:
Name Type Description
obj Object the object to test
name String the name of the function argument being tested

<static> assertNumber(obj, name)

Assert that the argument is a number; else throw an Error.
Parameters:
Name Type Description
obj Number the object to test
name String the name of the function argument being tested

<static> assertNumberBetween(obj, obj1, obj2, name)

Assert that the argument is a number within and including a specific range; else throw an Error.
Parameters:
Name Type Description
obj Number the object to test
obj1 Number the lower boundary (must be a number)
obj2 Number the upper boundary (must be a number)
name String the name of the function argument being tested

<static> assertNumberComparison(number, name, operator, operand, operandName)

Assert that the argument is a number that passes the specified comparison; else throw an Error.
Parameters:
Name Type Description
number Number the number to test
name String the name of the number being tested
operator String the comparison operator, one of "<", "<=", " ==", " !=", ">", or ">="
operand Number the number to test against
operandName String the name of the operand

<static> assertObject(obj, name)

Assert that the argument is a non null object; else throw an Error.
Parameters:
Name Type Description
obj Object the object to test
name String the name of the function argument being tested

<static> assertObject(obj, name, key)

Assert that the first argument has the third argument as its key; else throw an Error.
Parameters:
Name Type Description
obj Object the object to test
name String the name of the the object being tested
key String the key to test

<static> assertOptionalArray(obj, name)

Assert that the argument is an array or undefined; else throw an Error.
Parameters:
Name Type Description
obj Array the object to test
name String the name of the function argument being tested

<static> assertOptionalBoolean(obj, name)

Assert that the argument is either null/undefined or a boolean; else throw an Error.
Parameters:
Name Type Description
obj Object the object to test
name String the name of the function argument being tested

<static> assertOptionalElement(obj, name)

Assert that the argument is either null/undefined or an element; else throw an Error.
Parameters:
Name Type Description
obj Object the object to test
name String the name of the function argument being tested

<static> assertOptionalFunction(obj, name)

Assert that the argument is either null/undefined or a function; else throw an Error.
Parameters:
Name Type Description
obj Object the object to test
name String the name of the function argument being tested

<static> assertOptionalInstanceOf(obj, base, name, baseName)

Parameters:
Name Type Description
obj Object the object to test
base Function a base class
name String the name of the function argument being tested
baseName String the name of the base class

<static> assertOptionalJQueryElement($element, sName)

Assert that the argument is either null/undefined or a JQuery object containing an element; else throw an error.
Parameters:
Name Type Description
$element jquery the jquery element to test
sName String the name of the object being tested

<static> assertOptionalJQueryElements($elements, sName, nOptionalExpectedNumElements)

Assert that the argument is either null/undefined or a JQuery object containing one or more elements; else throw an error.
Parameters:
Name Type Description
$elements jquery the jquery elements to test
sName String the name of the object being tested
nOptionalExpectedNumElements integer the optional expected number of elements. If not specified the function validates that there is at least one element.

<static> assertOptionalNumber(obj, name)

Assert that the argument is either null/undefined or a number; else throw an Error.
Parameters:
Name Type Description
obj String the object to test
name String the name of the function argument being tested

<static> assertOptionalObject(obj, name)

Assert that the argument is either null/undefined or an object; else throw an Error.
Parameters:
Name Type Description
obj Object the object to test
name String the name of the function argument being tested

<static> assertOptionalRegularExpression(oObj, sName)

Assert that the argument is either null or a regular expression; else throw an Error.
Parameters:
Name Type Description
oObj RegularExpression the object to test
sName String the name of the function argument being tested

<static> assertOptionalString(obj, name)

Assert that the argument is either null/undefined or a string; else throw an Error.
Parameters:
Name Type Description
obj String the object to test
name String the name of the function argument being tested

<static> assertOptionalValidEnum(obj, either, the)

Assert that the specified object is either null/undefined or one of the possible values in the enumeration; else throw an Error
Parameters:
Name Type Description
obj Object the object to test &@param {String} name the name of the function argument being tested
either Array | Object an array or an associative map of possible enum values
the String name of the enumeration

<static> assertRegularExpression(oObj, sName)

Assert that the argument is a regular expression; else throw an Error.
Parameters:
Name Type Description
oObj RegularExpression the object to test
sName String the name of the function argument being tested

<static> assertString(obj, name)

Assert that the argument is a string; else throw an Error.
Parameters:
Name Type Description
obj String the object to test
name String the name of the function argument being tested

<static> assertTrue(obj, the)

Asserts that the given argument is strictly true
Parameters:
Name Type Description
obj Object the object to test
the String name of the assertion

<static> assertTrue(obj, the)

Asserts that the given argument is strictly false
Parameters:
Name Type Description
obj Object the object to test
the String name of the assertion

<static> assertTypeOf(obj, sExpectedTypeOf, name)

Parameters:
Name Type Description
obj Object the object to test
sExpectedTypeOf String the expected string when calling typeof(obj)
name String the name of the obj being tested

<static> assertValidEnum(obj, either, the)

Assert that the specified object is one of the possible values in the enumeration; else throw an Error
Parameters:
Name Type Description
obj Object the object to test &@param {String} name the name of the function argument being tested
either Array | Object an array or an associative map of possible enum values
the String name of the enumeration

<static> assertVersionCompatible() → {Number}

Validate that an imported version match the currently supported. If the imported has a lower number; a negative number, which indicates the position of the first difference, is returned. Differences in the last position is ignored.
Throws:
for parse errors and if the imported version is higher.
Type
module:obitech-framework/jsx#jsx.OBIError
Returns:
Zero for exact match or a negative numbers indicating where the first diference is found.
Type
Number

<static> callFunction(sDescription, fFunction, fOnError, logger, console) → {Error}

Call a function and do appropriate error handling.
Parameters:
Name Type Argument Description
sDescription String
A description to be included in error messages.
fFunction Function
a function taking no parameters
fOnError Function <optional>
an optional er taking an error parameter
logger Object <optional>
an optional logger, which will be used to report errors that are not consumed by an error
console Object <optional>
an optional console. Any errors that cannot be logged to logged will use either system console or passed in console
Returns:
Any error raised by the function or null of the operation completed successfully.
Type
Error

<static> clock(timestamp)

simple logical clock usage: jsx.clock() returns current counter, and increments internal counter by 1
Parameters:
Name Type Description
timestamp
passing it a value will loosely sync this clock with the given timestamp such that its internal counter is at least equal to the specified value

<static> clone(obj) → {T}

This method enables you to create a deep clone of the specified object.
Parameters:
Name Type Description
obj T The object, array or primitive that you want to clone.
Returns:
A clone of the specified object, array or primitive
Type
T

<static> compareVersionStrings(sVersionA, sVersionB) → {number}

Compare two three digit version strings separated by periods. Returns a negative number if the first one is lower, zero if the same, a positive number if the first one is higher. The absolute value of the returned value is the first position on which the two versions differ.
Parameters:
Name Type Description
sVersionA string the first version number
sVersionB string the second version number
Returns:
Type
number

<static> createErrorFromErrorPayload(oPayload, Optional) → {Error}

Creates an error object from a given error description which can be itself, an error, a string, or a json object. If stringify fails to process the object, we return that error instead.
Parameters:
Name Type Argument Description
oPayload Error | String | Object <optional>

Optional String
error code. Callers can access this via the sBITechErrorCode property on the returned object.
Returns:
error constructed from oPayload or null if oPayload and sErrorCode are both null
Type
Error

<static> createInstance(constructorFunc, args)

Creates an instance of the provided function passing provides args to the constructor function.
Parameters:
Name Type Description
constructorFunc
Constructor function
args
arguments array

<static> debounce(fCallback, nTimeoutDelay, oOptions)

This method is used to limit the number of times a function is executed. The callback will only be executed once after a 'nTimeoutDelay' from the last triggered event.
Parameters:
Name Type Description
fCallback function The executable function
nTimeoutDelay Number The debounce delay between the last triggered event and execution of the callback.
oOptions module:obitech-framework/jsx#JsxThrottleOptions

<static> defaultParam()

if val is undefined, returns defaultVal, else returns val Usage:
   var myFcn = function(x) {
      x = defaultParam(x, 20); // defaults to 20
      // do stuff with x
   }

<static> extend(subClass, baseClass)

This method enables you to implement inheritance by extending the specified baseClass with the specified subClass.
Parameters:
Name Type Description
subClass Function A reference to the subclass's constructor function.
baseClass Function A reference to the superclass's constructor function.

<static> freezeObject(obj, name) → {Object}

Freeze an object if the JavaScript engine supports Object.freeze.
Parameters:
Name Type Description
obj Object the object to freeze
name String the name of the function argument being tested
Returns:
The frozen object or the original object if freeze isn't supported
Type
Object

<static> generateUUID() → {String}

Returns a UUID like f81d4fae-7dec-41d0-a765-00a0c91e6bf6 RFC-4122 Version 4 compliant http://www.ietf.org/rfc/rfc4122.txt
Returns:
uuid
Type
String

<static> getErrorObject(category, message, innerError) → {obitech-framework/jsx#OBIError}

Create an error object suitable for throwing or passing as argument to onError methods.
Parameters:
Name Type Description
category

message

innerError

Returns:
error object
Type
obitech-framework/jsx#OBIError

<static> getTimeStamp() → {number}

Return a time stamp value with as high resulution as possible. This should only be used for computing time differences.
Returns:
time with milli second precision with an unknown base point.
Type
number

<static> identityFunctor(x, makeClone) → {T}

Returns a function that returns (a clone of) the parameter
Parameters:
Name Type Description
x T
makeClone boolean
Returns:
Type
T

<static> isArray(obj) → {Boolean}

Returns true if the argument is an array, else returns false. This is an alias for Array.isArray
Parameters:
Name Type Description
obj Object the object to test
Returns:
Type
Boolean

<static> isBoolean(obj) → {Boolean}

Returns true if obj is a boolean
Parameters:
Name Type Description
obj Object the object to test
Returns:
true if obj is a boolean
Type
Boolean

<static> isElement(obj) → {boolean}

Check if argument is a DOM element. Works for both XML and HTML elements.
Parameters:
Name Type Description
obj Object the object to test
Returns:
true if obj is a DOM element
Type
boolean

<static> isFunction(obj) → {boolean}

Check if argument is a function
Parameters:
Name Type Description
obj Object the object to test
Returns:
true if obj is a function
Type
boolean

<static> isInstanceOf(obj, base)

Parameters:
Name Type Description
obj Object the object to test
base Function a base class

<static> isInteger(obj) → {Boolean}

Returns true if obj is an integer
Parameters:
Name Type Description
obj Object the object to test
Returns:
true if obj is an integer
Type
Boolean

<static> isNotNull(obj) → {boolean}

Check if argument is NOT null or undefined.
Parameters:
Name Type Description
obj Object the object to test
Returns:
true if obj is either not null and not undefined
Type
boolean

<static> isNull(obj) → {boolean}

This is an alias for isNullOrUndefined
Parameters:
Name Type Description
obj Object the object to test
Returns:
true if obj is either null or undefined
Type
boolean

<static> isNullOrUndefined(obj) → {boolean}

Check if argument is null or undefined.
Parameters:
Name Type Description
obj Object the object to test
Returns:
true if obj is either null or undefined
Type
boolean

<static> isObject(obj) → {Boolean}

Returns true if obj is a non-null object
Parameters:
Name Type Description
obj Object the object to test
Returns:
true if obj is a non-null object
Type
Boolean

<static> isPrimitive(obj) → {Boolean}

Returns true if obj is primitive (undefined/null, number, string, boolean, symbol)
Parameters:
Name Type Description
obj Object the object to test
Returns:
true if obj is primitive
Type
Boolean

<static> isRegularExpression(oObj) → {Boolean}

Parameters:
Name Type Description
oObj Object the object to test
Returns:
true if oObj is an instance of RegExp
Type
Boolean

<static> isUndefined(obj) → {boolean}

This is an alias for isNullOrUndefined
Parameters:
Name Type Description
obj Object the object to test
Returns:
true if obj is is either null or undefined
Type
boolean

<static> jsx.deepEqual(obj1, obj2) → {Boolean}

Loosely based on qunit's deepEqual obj1 and obj2 are JSON objects functions and non plain objects are not supported!
Parameters:
Name Type Description
obj1 Object a plain object / array / primitive
obj2 Object a plain object / array / primitive
Returns:
true if obj1 and obj2 are equal (strict equality)
Type
Boolean

<static> jsx.overlaySettings(source, target, bClone)

Overlay settings from one settings object ontop of another, optionally referencing parts of source. Regular expressions and date types is not properly handled, only regular JSON types.
Parameters:
Name Type Argument Description
source object
source object
target object
target object
bClone boolean <optional>
optional flag to control of cloning should be done, default true

<static> memoize()

memoize a function Usage:
  var fib = jsx.memoize( function(n) {
     return (n <= 1="" 1)="" ?="" :="" fib(n-1)="" +="" fib(n-2);="" });="" <="" pre="">
    
Returns:
a memoized function

<static> openWindow(true, the, a)

A method to conditionally invoke window.open. In DESKTOP mode we never want to open a new window. Redirect instead. Otherwise we invoke window.open normally.
Parameters:
Name Type Description
true boolean if DESKTOP mode, false otherwise (REQUIRED)
the String path to redirect to/open in new window (REQUIRED)
a String name for the new window (OPTIONAL)

<static> parameterFunctor()

Usage:
  var name = parameterFunctor("tim");
  name();      // returns "tim"
  name("rob"); // sets its internal state to "rob"; returns "rob"
  name();      // returns "rob"
Returns:
function closure over the given parameter. can get/set its value

<static> parseIntExact() → {Number}

Parse an integer.
Returns:
the result
Type
Number

<static> parseVersionString() → {Array.<Number>}

Parse a three digit version string separated by periods.
Returns:
An array with three integers
Type
Array.<Number>

<static> throttle(fCallback, nTimeoutDelay, oOptions)

This method is used to limit the number of times a function is executed. By default, the callback will only be executed once every 'nTimeoutDelay'.
Parameters:
Name Type Description
fCallback function The executable function
nTimeoutDelay Number The throttle delay between each execution of the function
oOptions module:obitech-framework/jsx#JsxThrottleOptions

Type Definitions

JsxThrottleOptions

This object defines the options for the jsx.throttle method.
Type:
  • Object
Properties:
Name Type Description
debounce boolean Whether to use debounce approach instead of 'throttle'. Default: false.
immediateOnFirst boolean Whether to execute the callback function the first time throttle wrapper is called. Default: false.