LinkableHashMap Class
Allows dynamically creating instances of objects inheriting ILinkableObject at runtime. The session state is an Array of DynamicState objects.
Constructor
LinkableHashMap
-
typeRestriction
Parameters:
-
typeRestrictionClassIf specified, this will limit the type of objects that can be added to this LinkableHashMap.
Item Index
Methods
- _createAndSaveNewObject
- _initObjectByClassName
- _lockObject
- _runCallbacksImmediately
- addDisposeCallback
- addGroupedCallback
- addImmediateCallback
- delayCallbacks
- dispose
- generateUniqueName
- getNames
- getObject
- getObjects
- getSessionState
- handleGroupedCallback
- objectIsLocked
- removeAllObjects
- removeCallback
- removeObject
- renameObject
- requestObject
- requestObjectCopy
- resumeCallbacks
- setNameOrder
- setSessionState
- trigger
- triggerCallbacks
Properties
- _callbackEntries
- _childListCallbacks
- _delayCount
- _disposeCallbackEntries
- _lastTriggerStackTrace
- _linkableObject
- _nameIsLocked
- _nameToObjectMap
- _objectToNameMap
- _oldEntries
- _orderedNames
- _precallback
- _previousNameMap
- _runCallbacksCompleted
- _runCallbacksIsPending
- _typeRestriction
- _typeRestrictionClassName
- _wasDisposed
- addCallback_stackTrace
- callback
- callbacksAreDelayed
- childListCallbacks
- CLASS_NAME static
- context
- NS static
- recursionCount
- removeCallback_stackTrace
- schedule
- SESSIONABLE static
- triggerCounter
- triggered
- triggeredAgain
- typeRestriction
- wasDisposed
Methods
_createAndSaveNewObject
-
name -
classDef -
lockObject
Parameters:
-
nameStringThe identifying name to associate with a new object.
-
classDefClassThe Class definition used to instantiate a new object.
-
lockObjectBooleanIf this is set to true, lockObject() will be called on the given name.
_initObjectByClassName
-
name -
className -
lockObject
If there is an existing object associated with the specified name, it will be kept if it is the specified type, or replaced with a new instance of the specified type if it is not.
Parameters:
-
nameStringThe identifying name of a new or existing object. If this is null, a new one will be generated.
-
classNameStringThe qualified class name of the desired object type.
-
lockObjectBooleanIf this is set to true, lockObject() will be called on the given name.
Returns:
The object associated with the given name, or null if an error occurred.
_lockObject
-
name
This function will lock an object in place for a given identifying name. If there is no object using the specified name, this function will have no effect.
Parameters:
-
nameStringThe identifying name of an object to lock in place.
_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
-
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
()
This function removes all objects from this LinkableHashMap. adds implementaion to dispose
generateUniqueName
-
baseName
This will generate a new name for an object that is different from all the names of objects previously used in this LinkableHashMap.
Parameters:
-
baseNameStringThe name to start with. If the name is already in use, an integer will be appended to create a unique name.
getNames
-
filter
This function returns an ordered list of names in the hash map.
Parameters:
-
filterClassIf specified, names of objects that are not of this type will be filtered out.
Returns:
A copy of the ordered list of names of objects contained in this LinkableHashMap.
getObject
-
name
This function gets the object associated with the specified name.
Parameters:
-
nameStringThe identifying name to associate with an object.
Returns:
The object associated with the given name.
getObjects
-
filter
This function returns an ordered list of objects in the hash map.
Parameters:
-
filterClassIf specified, objects that are not of this type will be filtered out.
Returns:
An ordered Array of objects that correspond to the names returned by getNames(filter).
getSessionState
()
Array
This gets the session state of this composite object.
Returns:
An Array of DynamicState objects which compose the session state for this object.
handleGroupedCallback
()
Checks the context(s) before calling groupedCallback
objectIsLocked
-
name
This function will return true if the specified object was previously locked.
Parameters:
-
nameStringThe name of an object.
Returns:
removeAllObjects
()
This function attempts to removes all objects from this LinkableHashMap. Any objects that are locked will remain.
removeCallback
-
callback
This function will remove a callback that was previously added.
Parameters:
-
callbackFunctionThe function to remove from the list of callbacks.
removeObject
-
name
This function removes an object from the hash map.
Parameters:
-
nameStringThe identifying name of an object previously saved with setObject().
renameObject
-
oldName -
newName
This function will rename an object by making a copy and removing the original.
Parameters:
-
oldNameStringThe name of an object to replace.
-
newNameStringThe new name to use for the copied object.
Returns:
The copied object associated with the new name, or the original object if newName is the same as oldName.
requestObject
-
name -
classDef -
lockObject
This function creates an object in the hash map if it doesn't already exist. If there is an existing object associated with the specified name, it will be kept if it is the specified type, or replaced with a new instance of the specified type if it is not.
Parameters:
-
nameStringThe identifying name of a new or existing object.
-
classDefClassThe Class of the desired object type.
-
lockObjectBooleanIf this is true, the object will be locked in place under the specified name.
Returns:
The object under the requested name of the requested type, or null if an error occurred.
requestObjectCopy
-
newName -
objectToCopy
This function will copy the session state of an ILinkableObject to a new object under the given name in this LinkableHashMap.
Parameters:
-
newNameStringA name for the object to be initialized in this LinkableHashMap.
-
objectToCopyILinkableObjectAn object to copy the session state from.
Returns:
The new object of the same type, or null if an error occurred.
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.
setNameOrder
-
newOrder
This will reorder the names returned by getNames(). Any names appearing in newOrder that do not appear in getNames() will be ignored. Callbacks will be called if the new name order differs from the old order.
Parameters:
-
newOrderArrayThe new desired ordering of names.
setSessionState
-
newState -
removeMissingDynamicObjects
This sets the session state of this composite object.
Parameters:
-
newStateArrayAn Array of child name Strings or DynamicState objects containing the new values and types for child ILinkableObjects.
-
removeMissingDynamicObjectsBooleanIf true, this will remove any child objects that do not appear in the session state. As a special case, a null session state will result in no change regardless of the removeMissingDynamicObjects value.
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.
_lastTriggerStackTrace
String
private
for debugging only... will be set when debug==true
_nameIsLocked
Object
private
maps an identifying name to a value of true if that name is locked.
_nameToObjectMap
Object
private
maps an identifying name to an object
_objectToNameMap
Map
private
maps an object to an identifying name
_oldEntries
Array
private
_orderedNames
Array
private
an ordered list of names appearing in _nameToObjectMap
_precallback
Function
protected
This is the function that gets called immediately before every callback.
_previousNameMap
Object
private
maps a previously used name to a value of true. used when generating unique names.
_runCallbacksCompleted
Boolean
private
This flag is used in _runCallbacksImmediately() to detect when a recursive call has completed running all the callbacks.
_runCallbacksIsPending
Boolean
private
If this is true, it means triggerCallbacks() has been called while delayed was true.
_typeRestriction
Class
private
restricts the type of object that can be stored
_typeRestrictionClassName
String
private
qualified class name of _typeRestriction
_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.
childListCallbacks
ChildListCallbackInterface
public
This is an interface for adding and removing callbacks that will get triggered immediately when the list of child objects changes.
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.
NS
String
public
static
temporary solution to save the namespace for this class/prototype
Default: weavecore
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
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
typeRestriction
Class
public
The child type restriction, or null if there is none.
wasDisposed
Boolean
public
This flag becomes true after dispose() is called.
