jgrouse.coreutil


module jgrouse.coreutil
Useful utilities
Defined in jgrouse/coreutil.js

Variable Summary
Global handler for exceptions thrown in event listeners.

Function Summary
bind(Object obj, String methodName, Array otherArgs)
bind(Object obj, Function method, Array otherArgs)
Return a function that is bound to given object
bindAsEventListener(Object obj, String methodName, Array otherArgs)
bindAsEventListener(Object obj, Function method, Array otherArgs)
Return function that bound to given object has interface event listener - function(event)
copyAll(Object dst, Object src)
Copy all attributes from source to destination
copyData(Object dst, Object src)
Copy only data attributes from src to dst.
copyNew(Object dst, Object src)
Copy new attributes from src to dst.
delegate(Object dst, String memberName, Object memberClass, [String[] exclude])
delegate(Object dst, String memberName, String memberClassName, [String[] exclude])
delegate(Object dst, Object member, Object memberClass, [String[] exclude])
delegate(Object dst, Object member, Object memberClassName, [String[] exclude])
Create methods in object that delegating to methods of given member.
isEmpty(Object obj)
Checks if the structure is empty, i.e.
objectComparator(Object obj1, Object obj2)
Compare two objects.
function perlify(function func, String[] argNames)
Allow falling of function that accepts a number of parameters in Perl way.
search(array arr, Object item, [comparatorFunction comparator])
Searches for item in array
syncData(Object dst, Object src, watcherFunction watcher)
Copy all changed attributes from src to dst and invoke callback for every changed attribute or every deleted attribute
toArray(Object data)
Converts argument to array, if possible.

Function Interface Summary
int comparatorFunction(Object obj1, Object obj2)
Signature of function that compares two objects
watcherFunction(Object dst, String propertyName, Object propertyValue, Object oldValue)
Signature of watcher function

Variable Details

variable eventExceptionHandler

Global handler for exceptions thrown in event listeners. Signature is function(event, exception) returns true if exception should be suppressed, otherwise it would be rethrown
Defined in jgrouse.coreutil

Function Details

function bind

bind(Object obj, String methodName, Array otherArgs)
bind(Object obj, Function method, Array otherArgs)
Return a function that is bound to given object
Parameters:
Option 1
obj - object to be applied as 'this' for the function
methodName - name of method to be bound
otherArgs - additional arguments that should be added when calling method
Option 2
obj - object to be applied as 'this' for the function
method - function to be bound
otherArgs - additional arguments that should be added when calling method
Returns:
function bound to given object
Defined in jgrouse.coreutil

function bindAsEventListener

bindAsEventListener(Object obj, String methodName, Array otherArgs)
bindAsEventListener(Object obj, Function method, Array otherArgs)
Return function that bound to given object has interface event listener - function(event)
Parameters:
Option 1
obj - object to be applied as 'this' for the function
methodName - name of method to be bound
otherArgs - additional arguments that should be added when calling method
Option 2
obj - object to be applied as 'this' for the function
method - function to be bound
otherArgs - additional arguments that should be added when calling method
Defined in jgrouse.coreutil

function copyAll

copyAll(Object dst, Object src)
Copy all attributes from source to destination
Parameters:
dst - object to receive attributes
src - object that provides attributes
Defined in jgrouse.coreutil

function copyData

copyData(Object dst, Object src)
Copy only data attributes from src to dst. Functions, etc are not included
Parameters:
dst - object to receive attributes
src - object that provides attributes
Defined in jgrouse.coreutil

function copyNew

copyNew(Object dst, Object src)
Copy new attributes from src to dst. New attributes are the ones that that are not defined in dst
Parameters:
dst - object to receive attributes
src - object that provides attributes
Defined in jgrouse.coreutil

function delegate

delegate(Object dst, String memberName, Object memberClass, [String[] exclude])
delegate(Object dst, String memberName, String memberClassName, [String[] exclude])
delegate(Object dst, Object member, Object memberClass, [String[] exclude])
delegate(Object dst, Object member, Object memberClassName, [String[] exclude])
Create methods in object that delegating to methods of given member. For example, if foo.bar.Bla has a member boo with method doThis , then delegating method would be added foo.bar.Bla.doThis = function() {this.boo.doThis(arguments)}. Note: this call would copy only methods that do not exist in dst.
Parameters:
Option 1
dst - object that should be enriched. Typically would be prototype of class
memberName - name of member that is used as delegate
memberClass - member's prototype (structure with all members of the delegate)
[exclude] - array of member's method names that should not be delegated to dst
Option 1a
dst - object that should be enriched. Typically would be prototype of class
memberName - name of member that is used as delegate
memberClassName - member's class name
[exclude] - array of member's method names that should not be delegated to dst
Option 2
dst - object that should be enriched. Typically would be prototype of class
member - object that is used as delegate
memberClass - member's prototype (structure with all members of the delegate)
[exclude] - array of member's method names that should not be delegated to dst
Option 2a
dst - object that should be enriched. Typically would be prototype of class
member - name of member that is used as delegate
memberClassName - member's prototype (structure with all members of the delegate)
[exclude] - array of member's method names that should not be delegated to dst
Defined in jgrouse.coreutil

function isEmpty

isEmpty(Object obj)
Checks if the structure is empty, i.e. does not have any members
Parameters:
obj structure
Returns:
true if structure has at least one member
Defined in jgrouse.coreutil

function objectComparator

objectComparator(Object obj1, Object obj2)
Compare two objects. If both objects have method equals then it is used for comparison
Parameters:
obj1 - first object to compare
obj2 - second object
Returns:
true if first object equals to the second
Defined in jgrouse.coreutil

function perlify

function perlify(function func, String[] argNames)
Allow falling of function that accepts a number of parameters in Perl way. Example:
   foo = jgrouse.perlify(function(arg1, arg2, arg3)
   {
     //do something
   }, ['arg1', 'arg2', 'arg3'])
   ...
   // invoke it the usual way
   foo('bebebe', 32, 'boo');
   // invoke it the Perl way
   foo({arg2:'boo', arg3:32, arg1:'bebebe'});
	
Parameters:
func - target function
argNames - names of arguments in order in which they appear in the target function
Defined in jgrouse.coreutil

function search

search(array arr, Object item, [comparatorFunction comparator])
Searches for item in array
Parameters:
arr - array containing data
item - item that is being searched for
[comparator] function
Returns:
the index where item was found or -1 otherwise
Defined in jgrouse.coreutil

function syncData

syncData(Object dst, Object src, watcherFunction watcher)
Copy all changed attributes from src to dst and invoke callback for every changed attribute or every deleted attribute
Parameters:
dst - object to receive attributes
src - object that provides attributes
watcher - function to be called for every mismatch.
Defined in jgrouse.coreutil

function toArray

toArray(Object data)
Converts argument to array, if possible. If data is array, then copy of data is returned. If data has method toArray then the result of that method is returned. If data has property length, then it is assumed that it is possible to iterate over elements of data as if over array. If neither of these conditions are met, then empty array is returned.
Parameters:
data - object that should be converted to array
Returns:
result of conversion to array
Defined in jgrouse.coreutil

Function Interface Details

ifunction comparatorFunction

int comparatorFunction(Object obj1, Object obj2)
Signature of function that compares two objects
Parameters:
obj1 - first object
obj2 - second object
Returns:
-1 if obj1 < obj2; 0 if obj1 == obj2; 1 if obj1 > obj2
Defined in jgrouse.coreutil

ifunction watcherFunction

watcherFunction(Object dst, String propertyName, Object propertyValue, Object oldValue)
Signature of watcher function
Parameters:
dst - target object
propertyName - name of changed property
propertyValue - new value of property
oldValue - old value of property
Defined in jgrouse.coreutil