Inheritance
Inheritance lets you define reusable base objects and derive new ones with small overrides.
Compdown uses two keys:
_id: defines a reusable template_extends: references an existing_idin the same array
Where inheritance works
compositionscompositions[].layers_timeline.layers
How merging works
- Object values are merged deeply.
- Array values are replaced (not concatenated).
- Scalar values are overridden by the child.
Composition example
yaml
compositions:
- _id: sceneBase
name: Scene-01
duration: 30
framerate: 24
color: ff8000
- _extends: sceneBase
name: Scene-02Layer example (inside _timeline)
yaml
_timeline:
layers:
- _id: textBase
name: Base
type: text
text: Hello
fontSize: 96
transform:
position: [960, 540]
opacity: 100
- _extends: textBase
name: Title
text: Welcome
transform:
opacity: 85Result:
Titleinheritstype,fontSize, andtransform.positiontransform.opacityis overridden to85
Layer example (inside a composition)
yaml
compositions:
- name: Main
layers:
- _id: nullBase
name: Base Null
type: null
enabled: false
- _extends: nullBase
name: ControllerValidation rules
Compdown fails validation when:
_extendspoints to an unknown_id_idis duplicated in the same array- inheritance is circular (
a -> b -> a) _idor_extendsis not a non-empty string