summaryrefslogtreecommitdiff
path: root/core/gjs/src/astalify.ts
diff options
context:
space:
mode:
authorKevin <[email protected]>2024-10-09 20:40:42 -0300
committerGitHub <[email protected]>2024-10-09 20:40:42 -0300
commitb5fc6cd12c7d62a4e89fc9c2915c61f8c19900aa (patch)
treee4dd92547856f5f4246f2536ffd6ab15049422ba /core/gjs/src/astalify.ts
parente6c35cb90f01149928baaa6959f5e1744efbb9b2 (diff)
parent0def6d7e9fd8b66220171ee228f0e845ed6edb57 (diff)
Merge branch 'Aylur:main' into main
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)
}