mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-25 08:06:51 +00:00
Add nodes with render and transform
This commit is contained in:
22
src/nodes/ObjectNode.ts
Normal file
22
src/nodes/ObjectNode.ts
Normal 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>`
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user