API Docs for: 1.0.0
Show:

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:

  • typeRestriction Class

    If specified, this will limit the type of objects that can be added to this LinkableHashMap.

Methods

_createAndSaveNewObject

(
  • name
  • classDef
  • lockObject
)
private

Parameters:

  • name String

    The identifying name to associate with a new object.

  • classDef Class

    The Class definition used to instantiate a new object.

  • lockObject Boolean

    If this is set to true, lockObject() will be called on the given name.

_initObjectByClassName

(
  • name
  • className
  • lockObject
)
ILinkableObject private

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:

  • name String

    The identifying name of a new or existing object. If this is null, a new one will be generated.

  • className String

    The qualified class name of the desired object type.

  • lockObject Boolean

    If this is set to true, lockObject() will be called on the given name.

Returns:

ILinkableObject:

The object associated with the given name, or null if an error occurred.

_lockObject

(
  • name
)
private

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:

  • name String

    The identifying name of an object to lock in place.

_runCallbacksImmediately

(
  • preCallbackParams
)
protected final

This function runs callbacks immediately, ignoring any delays. The preCallback function will be called with the specified preCallbackParams arguments.

Parameters:

  • preCallbackParams Object

    The 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:

  • relevantContext Object

    If 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.

  • callback Function

    The 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:

  • relevantContext Object

    If 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.

  • groupedCallback Function

    The callback function that will only be allowed to run during a scheduled time each frame. It must not require any parameters.

  • triggerCallbackNow Boolean

    If 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:

  • relevantContext Object

    If 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.

  • callback Function

    The function to call when callbacks are triggered.

  • runCallbackNow Boolean

    If this is set to true, the callback will be run immediately after it is added.

  • alwaysCallLast Boolean

    If 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:

  • baseName String

    The name to start with. If the name is already in use, an integer will be appended to create a unique name.

getNames

(
  • filter
)
Array

This function returns an ordered list of names in the hash map.

Parameters:

  • filter Class

    If specified, names of objects that are not of this type will be filtered out.

Returns:

Array:

A copy of the ordered list of names of objects contained in this LinkableHashMap.

getObject

(
  • name
)
ILinkableObject

This function gets the object associated with the specified name.

Parameters:

  • name String

    The identifying name to associate with an object.

Returns:

ILinkableObject:

The object associated with the given name.

getObjects

(
  • filter
)
Array

This function returns an ordered list of objects in the hash map.

Parameters:

  • filter Class

    If specified, objects that are not of this type will be filtered out.

Returns:

Array:

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:

Array:

An Array of DynamicState objects which compose the session state for this object.

handleGroupedCallback

()

Checks the context(s) before calling groupedCallback

objectIsLocked

(
  • name
)
Boolean

This function will return true if the specified object was previously locked.

Parameters:

  • name String

    The name of an object.

Returns:

Boolean:

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:

  • callback Function

    The function to remove from the list of callbacks.

removeObject

(
  • name
)

This function removes an object from the hash map.

Parameters:

  • name String

    The identifying name of an object previously saved with setObject().

renameObject

(
  • oldName
  • newName
)
ILinkableObject

This function will rename an object by making a copy and removing the original.

Parameters:

  • oldName String

    The name of an object to replace.

  • newName String

    The new name to use for the copied object.

Returns:

ILinkableObject:

The copied object associated with the new name, or the original object if newName is the same as oldName.

requestObject

(
  • name
  • classDef
  • lockObject
)
Object

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:

  • name String

    The identifying name of a new or existing object.

  • classDef Class

    The Class of the desired object type.

  • lockObject Boolean

    If this is true, the object will be locked in place under the specified name.

Returns:

Object:

The object under the requested name of the requested type, or null if an error occurred.

requestObjectCopy

(
  • newName
  • objectToCopy
)
ILinkableObject

This function will copy the session state of an ILinkableObject to a new object under the given name in this LinkableHashMap.

Parameters:

  • newName String

    A name for the object to be initialized in this LinkableHashMap.

  • objectToCopy ILinkableObject

    An object to copy the session state from.

Returns:

ILinkableObject:

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:

  • newOrder Array

    The new desired ordering of names.

setSessionState

(
  • newState
  • removeMissingDynamicObjects
)

This sets the session state of this composite object.

Parameters:

  • newState Array

    An Array of child name Strings or DynamicState objects containing the new values and types for child ILinkableObjects.

  • removeMissingDynamicObjects Boolean

    If 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

_linkableObject

ILinkableObject 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

_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.