Class ops.StepsCache
Defined in: StepsCache.js.
Constructor Attributes | Constructor Name and Description |
---|---|
ops.StepsCache(rootElement, bucketSize, restoreBookmarkPosition)
Implementation of a step to DOM point lookup cache.
|
Field Attributes | Field Name and Description |
---|---|
<static> |
ops.StepsCache.ENABLE_CACHE_VERIFICATION
Enable or disable cache verification operation after every modification.
|
Method Attributes | Method Name and Description |
---|---|
<static> |
ops.StepsCache.Bookmark()
|
<inner> |
clearNodeId(node)
|
damageCacheAfterStep(inflectionStep)
Mark all steps beyond inflectionStep as no longer accurate.
|
|
<inner> |
findBookmarkedAncestor(node)
Finds the nearest ancestor node that has an associated bookmark
|
<inner> |
getBucket(steps)
Returns the closest quantized step at or before the requested step
|
<inner> |
getClosestBookmark(steps)
Returns the closest undamaged bookmark before or at the specified step
|
<inner> |
getDestinationBucket(steps)
Returns the closest quantized step at or just after the requested step
|
<inner> |
getNodeBookmark(node)
Fetches (or creates) a bookmark for the specified node.
|
<inner> |
getNodeId(node)
|
<inner> |
getUndamagedBookmark(bookmark)
Returns the closest undamaged bookmark before (or equal to) the supplied bookmark
|
<inner> |
insertBookmark(previousBookmark, newBookmark)
Insert a bookmark into the cache chain just after the previous bookmark
|
<inner> |
inspectBookmarks(bookmark1, bookmark2)
Return a summary string of the supplied bookmark node id(s)
|
<inner> |
isAlreadyInOrder(previousBookmark, newBookmark)
Returns true if the newBookmark is already directly on or after the previous bookmark
|
<inner> |
isUndamagedBookmark(bookmark)
Returns true if the specified bookmark is undamaged
|
<inner> |
isValidBookmarkForNode(node, bookmark)
The element might have been cloned from another part of the document and have a stale or duplicate
nodeId
|
<inner> |
removeBookmark(currentBookmark)
Remove a bookmark from the cache chain
|
<inner> |
repairCacheUpToStep(currentIteratorStep)
Signal that all bookmarks up to the specified step have been iterated over and are up-to-date.
|
<inner> |
setNodeId(node)
|
setToClosestDomPoint(node, offset, iterator)
Set the iterator to the closest known position before or at the requested node & offset, returning the number
of steps from position 0.
|
|
setToClosestStep(steps, iterator)
Set the iterator to the closest known position before or at the requested step, returning the number of steps
from position 0.
|
|
updateBookmark(steps, node)
Cache the current step, using the supplied node as the anchor
|
|
<inner> |
Run a series of verification checks against the complete cache to ensure it is operating
correctly.
|
Class Detail
ops.StepsCache(rootElement, bucketSize, restoreBookmarkPosition)
Implementation of a step to DOM point lookup cache.
A cache point ("bookmark") is created each time updateBookmark is called, saving the number of steps from the root
node to the bookmarked node. This cached point is linked to the node via a unique identifier.
The cache works by tracking "damage" to it's bookmarks (via steps inserted & removal). As re-iteration over the
damaged sections occur, the bookmarks are updated, and the damage repaired.
A visual example of the cache during various states is as follows:
legend: -=good bookmark, x=damaged bookmark, !=indeterminate bookmark, ?=requested step,
- Parameters:
- {!Element} rootElement
- {!number} bucketSize
- Minimum number of steps between cache points
- {!function(!number|!core.PositionIterator):undefined} restoreBookmarkPosition
- Fine-tune the iterator position after it is set to a specific bookmark location.
Field Detail
<static>
ops.StepsCache.ENABLE_CACHE_VERIFICATION
Enable or disable cache verification operation after every modification. VERY SLOW.
This is primarily used in testing or during interactive diagnostics
Method Detail
<static>
ops.StepsCache.Bookmark()
<inner>
{undefined}
clearNodeId(node)
- Parameters:
- {!Element} node
- Returns:
- {undefined}
{undefined}
damageCacheAfterStep(inflectionStep)
Mark all steps beyond inflectionStep as no longer accurate. Note, if a negative value
is passed in it is treated as a -1, and the whole cache will be cleared.
- Parameters:
- {!number} inflectionStep
- Returns:
- {undefined}
<inner>
{?ops.StepsCache.Bookmark}
findBookmarkedAncestor(node)
Finds the nearest ancestor node that has an associated bookmark
- Parameters:
- {!Node} node
- Returns:
- {?ops.StepsCache.Bookmark}
<inner>
{!number}
getBucket(steps)
Returns the closest quantized step at or before the requested step
- Parameters:
- {!number} steps
- Returns:
- {!number}
<inner>
{!ops.StepsCache.Bookmark}
getClosestBookmark(steps)
Returns the closest undamaged bookmark before or at the specified step
- Parameters:
- {!number} steps
- Returns:
- {!ops.StepsCache.Bookmark}
<inner>
{!number}
getDestinationBucket(steps)
Returns the closest quantized step at or just after the requested step
- Parameters:
- {!number} steps
- Returns:
- {!number}
<inner>
{!ops.StepsCache.Bookmark}
getNodeBookmark(node)
Fetches (or creates) a bookmark for the specified node.
- Parameters:
- {!Element} node
- Returns:
- {!ops.StepsCache.Bookmark}
<inner>
{!string}
getNodeId(node)
- Parameters:
- {!Node} node
- Returns:
- {!string}
<inner>
{!ops.StepsCache.Bookmark}
getUndamagedBookmark(bookmark)
Returns the closest undamaged bookmark before (or equal to) the supplied bookmark
- Parameters:
- {!ops.StepsCache.Bookmark} bookmark
- Returns:
- {!ops.StepsCache.Bookmark}
<inner>
{undefined}
insertBookmark(previousBookmark, newBookmark)
Insert a bookmark into the cache chain just after the previous bookmark
- Parameters:
- {!ops.StepsCache.Bookmark} previousBookmark
- {!ops.StepsCache.Bookmark} newBookmark
- Returns:
- {undefined}
<inner>
{!string}
inspectBookmarks(bookmark1, bookmark2)
Return a summary string of the supplied bookmark node id(s)
- Parameters:
- {!ops.StepsCache.Bookmark} bookmark1
- {?ops.StepsCache.Bookmark=} bookmark2
- Returns:
- {!string}
<inner>
{!boolean}
isAlreadyInOrder(previousBookmark, newBookmark)
Returns true if the newBookmark is already directly on or after the previous bookmark
- Parameters:
- {!ops.StepsCache.Bookmark} previousBookmark
- {!ops.StepsCache.Bookmark} newBookmark
- Returns:
- {!boolean}
<inner>
{!boolean}
isUndamagedBookmark(bookmark)
Returns true if the specified bookmark is undamaged
- Parameters:
- {!ops.StepsCache.Bookmark} bookmark
- Returns:
- {!boolean}
<inner>
{!boolean}
isValidBookmarkForNode(node, bookmark)
The element might have been cloned from another part of the document and have a stale or duplicate
nodeId
- Parameters:
- {!Node} node
- {!ops.StepsCache.Bookmark} bookmark
- Returns:
- {!boolean} True if the bookmark is actually for the supplied node
<inner>
{undefined}
removeBookmark(currentBookmark)
Remove a bookmark from the cache chain
- Parameters:
- {!ops.StepsCache.Bookmark} currentBookmark
- Returns:
- {undefined}
<inner>
{!ops.StepsCache.Bookmark}
repairCacheUpToStep(currentIteratorStep)
Signal that all bookmarks up to the specified step have been iterated over and are up-to-date. This allows
removed nodes and invalid bookmarks to be removed from the cache. This function will return the closest
undamaged bookmark just at or prior to the supplied step.
- Parameters:
- {!number} currentIteratorStep
- Returns:
- {!ops.StepsCache.Bookmark}
<inner>
{!string}
setNodeId(node)
- Parameters:
- {!Element} node
- Returns:
- {!string}
{!number}
setToClosestDomPoint(node, offset, iterator)
Set the iterator to the closest known position before or at the requested node & offset, returning the number
of steps from position 0.
- Parameters:
- {!Node} node
- {!number} offset
- {!core.PositionIterator} iterator
- Returns:
- {!number} Corresponding step for the current iterator position
{!number}
setToClosestStep(steps, iterator)
Set the iterator to the closest known position before or at the requested step, returning the number of steps
from position 0.
- Parameters:
- {!number} steps
- {!core.PositionIterator} iterator
- Returns:
- {!number} Corresponding step for the current iterator position
{undefined}
updateBookmark(steps, node)
Cache the current step, using the supplied node as the anchor
- Parameters:
- {!number} steps
- Current steps offset from position 0
- {!Node} node
- Returns:
- {undefined}
<inner>
{undefined}
verifyCache()
Run a series of verification checks against the complete cache to ensure it is operating
correctly. Note, this is VERY expensive, and should only be done when attempting to diagnose
caching problems
- Returns:
- {undefined}