Search:
jgrouse.coreutil
module jgrouse.coreutil
Useful utilities
Defined in jgrouse/coreutil.js
Variable Summary
Global handler for exceptions thrown in event listeners.
Function Summary
Return a function that is bound to given object
Return function that bound to given object has interface event listener - function(event)
Copy all attributes from source to destination
Copy only data attributes from src to dst.
Copy new attributes from src to dst.
Create methods in object that delegating to methods of given member.
isEmpty(Object obj)
Checks if the structure is empty, i.e.
Compare two objects.
Allow falling of function that accepts a number of parameters in Perl way.
Searches for item in array
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
Signature of function that compares two objects
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 functionmethodName - name of method to be boundotherArgs - additional arguments that should be added when calling method Option 2
obj - object to be applied as 'this' for the functionmethod - function to be boundotherArgs - additional arguments that should be added when calling method 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 functionmethodName - name of method to be boundotherArgs - additional arguments that should be added when calling method Option 2
obj - object to be applied as 'this' for the functionmethod - function to be boundotherArgs - additional arguments that should be added when calling methodfunction copyAll
copyAll(Object dst, Object src)
Copy all attributes from source to destination
Parameters:
dst - object to receive attributessrc - object that provides attributesfunction copyData
copyData(Object dst, Object src)
Copy only data attributes from src to dst. Functions, etc are not included
Parameters:
dst - object to receive attributessrc - object that provides attributesfunction 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 attributessrc - object that provides attributesfunction 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 classmemberName - name of member that is used as delegatememberClass - 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 classmemberName - name of member that is used as delegatememberClassName - 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 classmember - object that is used as delegatememberClass - 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 classmember - name of member that is used as delegatememberClassName - member's prototype (structure with all members of the delegate)[exclude] - array of member's method names that should not be delegated to dstfunction isEmpty
isEmpty(Object obj)
Checks if the structure is empty, i.e. does not have any members
Parameters:
obj structure 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 compareobj2 - second object 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:
Parameters:
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'});
func - target functionargNames - names of arguments in order in which they appear in the target functionfunction search
search(array arr, Object item, [comparatorFunction comparator])
Searches for item in array
Parameters:
arr - array containing dataitem - item that is being searched for[comparator] function 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 attributessrc - object that provides attributeswatcher - function to be called for every mismatch.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 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 objectobj2 - second object -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 objectpropertyName - name of changed propertypropertyValue - new value of propertyoldValue - old value of property