Decoupling the "How" from Compiler Code
In traditional web development, a compiler contains hundreds of lines of imperative DOM traversal code: finding containers, creating child elements, iterating arrays, and appending nodes.
When the DOM structure changes (e.g., migrating from table colgroups to CSS subgrid or wrapping cells in divs), engineers are forced to rewrite compiler source code. declarative-instructions solved this by inventing declarative assembly instructions.
The 4-Part Instruction Contract
Every instruction in instructions.json declares what to do without writing a single loop:
- destinationPath: A JSONPath query pointing to where elements mount (
$..*[?@.attributes['data-role'] == 'headerRoot']). - sourcePath: Where input data is read from (e.g.,
$.columnsor$.data). - templateKey: Key in
declarative-specused as the cloneable tag prototype. - func: Standard mapping function (
fromCollection,oneDimension, etc.).
Instruction Rule Example
{
"buildHeader": [
{
"destinationPath": "$",
"templateKey": "buildHeader",
"type": "single"
},
{
"destinationPath": "$..*[?@.attributes['data-role'] == 'headerRoot']",
"sourcePath": "$.columns",
"templateKey": "buildHeaderCell",
"func": "fromCollection"
}
]
}