CallbackCollection Class
This class manages a list of callback functions. If specified, the preCallback function will be called immediately before running each callback using the parameters passed to _runCallbacksImmediately(). This means if there are five callbacks added, preCallback() gets called five times whenever _runCallbacksImmediately() is called. An example usage of this is to make sure a relevant variable is set to the appropriate value while each callback is running. The preCallback function will not be called before grouped callbacks.
Constructor
CallbackCollection
-
preCallback
Parameters:
-
preCallbackFunctionAn optional function to call before each immediate callback.
Item Index
Methods
Properties
- _callbackEntries
- _delayCount
- _disposeCallbackEntries
- _entryLookup static
- _handlingGroupedCallbacks static
- _handlingRecursiveGroupedCallbacks static
- _initialized static
- _lastTriggerStackTrace
- _linkableObject
- _oldEntries
- _precallback
- _runCallbacksCompleted
- _runCallbacksIsPending
- _runCallbacksIsPending
- _triggeredEntries static
- _wasDisposed
- addCallback_stackTrace
- callback
- callbacksAreDelayed
- CLASS_NAME
- CLASS_NAME static
- context
- DEFAULT_TRIGGER_COUNT static
- NS
- NS static
- recursionCount
- removeCallback_stackTrace
- schedule
- SESSIONABLE static
- SESSIONABLE static
- STACK_TRACE_ADD static
- STACK_TRACE_REMOVE static
- STACK_TRACE_TRIGGER static
- triggerCounter
- triggered
- triggeredAgain
- wasDisposed
Methods
_handleGroupedCallbacks
()
private
static
This function gets called once per frame and allows grouped callbacks to run.
_runCallbacksImmediately
-
preCallbackParams
This function runs callbacks immediately, ignoring any delays. The preCallback function will be called with the specified preCallbackParams arguments.
Parameters:
-
preCallbackParamsObjectThe arguments to pass to the preCallback function given in the constructor.
addDisposeCallback
-
relevantContext -
callback
This will add a callback that will only be called once, when this callback collection is disposed.
Parameters:
-
relevantContextObjectIf this is not null, then the callback will be removed when the relevantContext object is disposed via SessionManager.dispose(). This parameter is typically a 'this' pointer.
-
callbackFunctionThe function to call when this callback collection is disposed.
addGroupedCallback
-
callbackCollection -
relevantContext -
groupedCallback -
triggerCallbackNow
Parameters:
-
callbackCollectionCallbackCollection -
relevantContextObject -
groupedCallbackFunction -
triggerCallbackNowBoolean
addGroupedCallback
-
relevantContext -
groupedCallback -
triggerCallbackNow
Adds a callback that will only be called during a scheduled time each frame. Grouped callbacks use a central trigger list, meaning that if multiple ICallbackCollections trigger the same grouped callback before the scheduled time, it will behave as if it were only triggered once. For this reason, grouped callback functions cannot have any parameters. Adding a grouped callback to a ICallbackCollection will undo any previous effects of addImmediateCallback() or addDisposeCallback() made to the same ICallbackCollection. The callback function will not be called recursively as a result of it triggering callbacks recursively.
Parameters:
-
relevantContextObjectIf this is not null, then the callback will be removed when the relevantContext object is disposed via SessionManager.dispose(). This parameter is typically a 'this' pointer.
-
groupedCallbackFunctionThe callback function that will only be allowed to run during a scheduled time each frame. It must not require any parameters.
-
triggerCallbackNowBooleanIf this is set to true, the callback will be triggered to run during the scheduled time after it is added.
addImmediateCallback
-
relevantContext -
callback -
runCallbackNow -
alwaysCallLast
This adds the given function as a callback. The function must not require any parameters. The callback function will not be called recursively as a result of it triggering callbacks recursively.
Parameters:
-
relevantContextObjectIf this is not null, then the callback will be removed when the relevantContext object is disposed via SessionManager.dispose(). This parameter is typically a 'this' pointer.
-
callbackFunctionThe function to call when callbacks are triggered.
-
runCallbackNowBooleanIf this is set to true, the callback will be run immediately after it is added.
-
alwaysCallLastBooleanIf this is set to true, the callback will be always be called after any callbacks that were added with alwaysCallLast=false. Use this to establish the desired child-to-parent triggering order.
delayCallbacks
()
This will increase the delay count by 1. To decrease the delay count, use resumeCallbacks(). As long as the delay count is greater than zero, effects of triggerCallbacks() will be delayed.
dispose
()
Call this when the callback entry is no longer needed.
dispose
()
This function will be called automatically when the object is no longer needed, and should not be called directly. Use disposeObject() instead so parent-child relationships get cleaned up automatically.
handleGroupedCallback
()
Checks the context(s) before calling groupedCallback
removeCallback
-
callback
This function will remove a callback that was previously added.
Parameters:
-
callbackFunctionThe function to remove from the list of callbacks.
removeGroupedCallback
-
callbackCollection -
groupedCallback
Parameters:
-
callbackCollectionCallbackCollection -
groupedCallbackFunction
resumeCallbacks
()
This will decrease the delay count by one if it is greater than zero. If triggerCallbacks() was called while the delay count was greater than zero, immediate callbacks will be called now.
trigger
()
Marks the entry to be handled later (unless already triggered this frame). This also takes care of preventing recursion.
triggerCallbacks
()
This will trigger every callback function to be called with their saved arguments. If the delay count is greater than zero, the callbacks will not be called immediately.
Properties
_callbackEntries
Array
private
This is a list of CallbackEntry objects in the order they were created.
_delayCount
Number
private
This is the number of times delayCallbacks() has been called without a matching call to resumeCallbacks(). While this is greater than zero, effects of triggerCallbacks() will be delayed.
Default: 0
_disposeCallbackEntries
Array
private
A list of CallbackEntry objects for when dispose() is called.
_entryLookup
Map
private
static
This maps a groupedCallback function to its corresponding GroupedCallbackEntry.
_handlingGroupedCallbacks
Boolean
private
static
True while handling grouped callbacks.
Default: false
_handlingRecursiveGroupedCallbacks
Boolean
private
static
True while handling grouped callbacks called recursively from other grouped callbacks.
Default: false
_initialized
Boolean
private
static
This gets set to true when the static _handleGroupedCallbacks() callback has been added as a frame listener.
Default: false
_lastTriggerStackTrace
String
private
for debugging only... will be set when debug==true
_oldEntries
Array
private
_precallback
Function
protected
This is the function that gets called immediately before every callback.
_runCallbacksCompleted
Boolean
private
This flag is used in _runCallbacksImmediately() to detect when a recursive call has completed running all the callbacks.
_runCallbacksIsPending
Boolean
private
This value keeps track of how many times callbacks were triggered, and is returned by the public triggerCounter accessor function. The value starts at 1 to simplify code that compares the counter to a previous value. This allows the previous value to be set to zero so change will be detected the first time the counter is compared. This fixes potential bugs where the base case of zero is not considered.
_runCallbacksIsPending
Boolean
private
If this is true, it means triggerCallbacks() has been called while delayed was true.
_triggeredEntries
Array
private
static
This is a list of GroupedCallbackEntry objects in the order they were triggered.
_wasDisposed
Boolean
private
This value is used internally to remember if dispose() was called.
Default: false
addCallback_stackTrace
String
public
This is a stack trace from when the callback was added.
callback
Function
public
This is the callback function.
callbacksAreDelayed
Boolean
public
While this is true, it means the delay count is greater than zero and the effects of triggerCallbacks() are delayed until resumeCallbacks() is called to reduce the delay count.
CLASS_NAME
String
public
temporary solution to save the className for this class/prototype
CLASS_NAME
String
public
static
TO-DO:temporary solution to save the CLASS_NAME constructor.name works for window object , but modular based won't work
context
Object
public
This is the context in which the callback function is relevant. When the context is disposed, the callback should not be called anymore.
DEFAULT_TRIGGER_COUNT
Number
public
static
The name of the property containing the name assigned to the object when the session state is generated.
Default: 1
NS
String
public
temporary solution to save the namespace for this class/prototype
NS
String
public
static
TO-DO:temporary solution to save the namespace for this class/prototype
recursionCount
Number
public
This is the current recursion depth. If this is greater than zero, it means the function is currently running.
removeCallback_stackTrace
String
public
This is a stack trace from when the callback was removed.
schedule
Number
public
This is 0 if the callback was added with alwaysCallLast=false, or 1 for alwaysCallLast=true
SESSIONABLE
String
public
static
TO-DO:temporary solution for checking class in sessionable
SESSIONABLE
String
public
static
TO-DO:temporary solution for checking class in sessionable
STACK_TRACE_ADD
String
private
static
Internal Static const properties for Debugging
Default: "This is the stack trace from when the callback was added."
STACK_TRACE_REMOVE
String
private
static
Internal Static const properties for Debugging
Default: "This is the stack trace from when the callback was removed."
STACK_TRACE_TRIGGER
String
private
static
Internal Static const properties for Debugging
Default: "This is the stack trace from when the callbacks were last triggered."
triggerCounter
Number
public
This counter gets incremented at the time that callbacks are triggered and before they are actually called. It is necessary in some situations to check this counter to determine if cached data should be used.
triggered
Boolean
public
If true, the callback was triggered this frame.
Default: false
triggeredAgain
Boolean
public
If true, the callback was triggered again from another grouped callback.
Default: false
wasDisposed
Boolean
public
This flag becomes true after dispose() is called.
