ContentTree

content. ContentTree

Efficient tree abstraction over a flat array of course content items. Builds O(1) lookup indexes on construction for parent-child, type, and ID queries. Pure data structure with no DB access — works on both server and client.

Constructor

new ContentTree(items)

Source:
Parameters:
Name Type Description
items Array.<Object> Flat array of content items (from a single course)

Members

byId :Map.<string, Object>

Description:
  • _id -> item
Source:
_id -> item
Type:
  • Map.<string, Object>

byParent :Map.<string, Array.<Object>>

Description:
  • _parentId -> [children]
Source:
_parentId -> [children]
Type:
  • Map.<string, Array.<Object>>

byType :Map.<string, Array.<Object>>

Description:
  • _type -> [items]
Source:
_type -> [items]
Type:
  • Map.<string, Array.<Object>>

config :Object|null

Source:
Type:
  • Object | null

course :Object|null

Source:
Type:
  • Object | null

items :Array.<Object>

Source:
Type:
  • Array.<Object>

Methods

getAncestors(itemId) → {Array.<Object>}

Description:
  • Walk up the parent chain. O(d) where d = depth.
Source:
Parameters:
Name Type Description
itemId string | Object
Returns:
Type
Array.<Object>

getById(id) → {Object|undefined}

Description:
  • O(1) lookup by ID
Source:
Parameters:
Name Type Description
id string | Object
Returns:
Type
Object | undefined

getByType(type) → {Array.<Object>}

Description:
  • O(1) type lookup
Source:
Parameters:
Name Type Description
type string
Returns:
Type
Array.<Object>

getChildren(parentId) → {Array.<Object>}

Description:
  • O(1) children lookup
Source:
Parameters:
Name Type Description
parentId string | Object
Returns:
Type
Array.<Object>

getComponentNames() → {Array.<string>}

Description:
  • O(1) — unique component names across the course
Source:
Returns:
Type
Array.<string>

getDescendants(rootId) → {Array.<Object>}

Description:
  • BFS traversal to find all descendants. O(n) where n = number of descendants.
Source:
Parameters:
Name Type Description
rootId string | Object
Returns:
Type
Array.<Object>

getSiblings(itemId) → {Array.<Object>}

Description:
  • O(1) siblings lookup (excludes the item itself)
Source:
Parameters:
Name Type Description
itemId string | Object
Returns:
Type
Array.<Object>