Add nodes with render and transform

This commit is contained in:
Misode
2020-05-24 02:40:14 +02:00
parent 135b229265
commit d96949c605
6 changed files with 129 additions and 2 deletions

22
src/nodes/ObjectNode.ts Normal file
View File

@@ -0,0 +1,22 @@
import { AbstractNode, NodeChildren, NodeMods } from './AbstractNode'
export class ObjectNode extends AbstractNode<any> {
private fields: NodeChildren
constructor(fields: NodeChildren, mods?: NodeMods<any>) {
super(mods)
this.fields = fields
Object.values(fields).forEach(child => {
child.setParent(this)
})
}
render(field: string, value: any) {
value = value || {}
return `<span>${field}:</span><div>
${Object.keys(this.fields).map(f => {
return '> ' + this.fields[f].render(f, value[f])
}).join('<br>')}
</div>`
}
}