This namespace contains definitions for static functions that eases the use of functions objects in the API.
- Source:
- mapspace/functions/functions.jsdoc
Methods
-
<static> cancelize(fn)
-
Returns a cancelable version of function fn.
A cancelable function is an asynchronous function (i.e., one whose last argument is a callback receiving an error plus zero or more return values) that (synchronously) returns a cancel() function. Calling cancel() should abort the asynchronous operation and call the callback with the arguments that were passed into cancel(). Calling cancel() twice, as with callbacks, is not guaranteed to be safe.
Wrap a non-cancellable asynchronous function into a cancelable one.
Calling cancel() on the returned function will not interrupt the execution of the original function; it will merely ignore its return value.
Usually, instead of wrapping your function, you want to implement cancel() yourself in order to have some abort logic. This utility function provides a straighforward solution for cases in which no custom abort logic is required.
Parameters:
Name Type Description fn
function Function to call.
- Source:
- mapspace/functions/functions.js
Returns:
Cancelable function.
- Type
- function
-
<static> chain(params)
-
Return a function that executes its arguments (which should be cancelable functions) in sequence, so that each of them passes its return values to the next. Execution is aborted if one of the functions returns an error; in that case the last function in the sequence (done function) is called with the error. Explanation of a cancelable function in
Mapspace.functions.cancelize
.Parameters:
Name Type Argument Description params
function <repeatable>
Functions to chain and a done function.
- Source:
- mapspace/functions/functions.js
Returns:
Function for chained execution. This function can receive any number of args but last one should be the done function, and all this args will be passed to all the functions chained.
- Type
- function
-
<static> delay(ms, done)
-
Perform a cancelable delay. This function just waits some milliseconds and finally executes done, or if it was canceled, executes done. It is a work around IE8 bug whereby a setTimeout callback may still be called after the corresponding clearTimeout is invoked. Explanation of a cancelable function in
Mapspace.functions.cancelize
.Parameters:
Name Type Description ms
number Delay in milliseconds.
done
function Done function.
- Source:
- mapspace/functions/functions.js
Returns:
Function for cancelation.
- Type
- function
-
<static> once(fn)
-
Returns a non-cancelable function that will execute fn only once.
Parameters:
Name Type Description fn
function Function to call.
- Source:
- mapspace/functions/functions.js
Returns:
Function callable only once.
- Type
- function
-
<static> retry(fn)
-
Returns a cancelable function that executes fn in a loop until it returns successfully. Explanation of a cancelable function in
Mapspace.functions.cancelize
.Parameters:
Name Type Description fn
function Function to iterate.
- Source:
- mapspace/functions/functions.js
Returns:
Function for infinite retry. This function can receive any number of args but last one should be the done function.
- Type
- function
-
<static> stopPropagation(evt)
-
Function that allows to stop propagation of a given event.
Parameters:
Name Type Description evt
evt Event.
- Source:
- mapspace/functions/functions.js
-
<static> tween(duration, update, done)
-
Loops the execution of a function 'update' several times in a given duration and sends the percentage (0..1) of time elapsed to that function. Uses the Javascript native function 'requestAnimationFrame' to re-execute the function in each frame rendering. This function is a cancelable one because returns a function that can cancel the process. Explanation of a cancelable function in
Mapspace.functions.cancelize
.Parameters:
Name Type Description duration
number Time in milliseconds to execute the function.
update
function Function to iterate.
done
function Function to call when process ends because duration has been passed away or because cancellation.
- Source:
- mapspace/functions/functions.js
Returns:
Function for cancellation.
- Type
- function