summaryrefslogtreecommitdiff
path: root/core/gjs/src/astalify.ts
diff options
context:
space:
mode:
Diffstat (limited to 'core/gjs/src/astalify.ts')
-rw-r--r--core/gjs/src/astalify.ts33
1 files changed, 16 insertions, 17 deletions
diff --git a/core/gjs/src/astalify.ts b/core/gjs/src/astalify.ts
index 85d7531..29e7a5f 100644
--- a/core/gjs/src/astalify.ts
+++ b/core/gjs/src/astalify.ts
@@ -25,18 +25,17 @@ function mergeBindings(array: any[]) {
function setProp(obj: any, prop: string, value: any) {
try {
+ // the setter method has to be used because
+ // array like properties are not bound correctly as props
const setter = `set_${snakeify(prop)}`
if (typeof obj[setter] === "function")
return obj[setter](value)
- if (Object.hasOwn(obj, prop))
- return (obj[prop] = value)
+ return (obj[prop] = value)
}
catch (error) {
console.error(`could not set property "${prop}" on ${obj}:`, error)
}
-
- console.error(`could not set property "${prop}" on ${obj}`)
}
export default function astalify<
@@ -183,6 +182,19 @@ export default function astalify<
return acc
}, [])
+ // setup bindings handlers
+ for (const [prop, binding] of bindings) {
+ if (prop === "child" || prop === "children") {
+ this.connect("destroy", binding.subscribe((v: any) => {
+ this._setChildren(v)
+ }))
+ }
+ this.connect("destroy", binding.subscribe((v: any) => {
+ setProp(this, prop, v)
+ }))
+ setProp(this, prop, binding.get())
+ }
+
// set children
const mergedChildren = mergeBindings(children.flat(Infinity))
if (mergedChildren instanceof Binding) {
@@ -208,19 +220,6 @@ export default function astalify<
}
}
- // setup bindings handlers
- for (const [prop, binding] of bindings) {
- if (prop === "child" || prop === "children") {
- this.connect("destroy", binding.subscribe((v: any) => {
- this._setChildren(v)
- }))
- }
- this.connect("destroy", binding.subscribe((v: any) => {
- setProp(this, prop, v)
- }))
- setProp(this, prop, binding.get())
- }
-
Object.assign(this, props)
setup?.(this)
}