2020-11-16 19:05:17 +01:00
|
|
|
import { cloneDeep } from "lodash/fp"
|
|
|
|
|
|
|
|
export class BaseStructure {
|
|
|
|
constructor(isScreen) {
|
|
|
|
this._isScreen = isScreen
|
|
|
|
this._children = []
|
2020-11-17 19:13:21 +01:00
|
|
|
this._json = {}
|
2020-11-16 19:05:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
addChild(child) {
|
|
|
|
this._children.push(child)
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
customProps(props) {
|
|
|
|
for (let key of Object.keys(props)) {
|
|
|
|
this._json[key] = props[key]
|
|
|
|
}
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
json() {
|
|
|
|
const structure = cloneDeep(this._json)
|
|
|
|
if (this._children.length !== 0) {
|
|
|
|
for (let child of this._children) {
|
|
|
|
if (this._isScreen) {
|
2024-09-07 20:02:36 +02:00
|
|
|
structure.props._children.push(child.json?.() || child)
|
2020-11-16 19:05:17 +01:00
|
|
|
} else {
|
2024-09-07 20:02:36 +02:00
|
|
|
structure._children.push(child.json?.() || child)
|
2020-11-16 19:05:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return structure
|
|
|
|
}
|
|
|
|
}
|