Constructor
new ContentTree(items)
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
Type:
- Object | null
course :Object|null
Type:
- Object | null
items :Array.<Object>
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>