Skip to content

Instantly share code, notes, and snippets.

@zerkalica
Created December 1, 2023 08:55
Show Gist options
  • Save zerkalica/147d50b75642c1099283f4d1178eb63c to your computer and use it in GitHub Desktop.
Save zerkalica/147d50b75642c1099283f4d1178eb63c to your computer and use it in GitHub Desktop.
hierarchical off links in mol
namespace $.$$ {
export const $gd_kit_page_current = undefined as undefined | $gd_kit_page
/*
Switch $mol_page to $gd_kit_page via context
@example
```ts
class $my_app extends $.$my_app {
@ $mol_memo.field
get $() {
return super.$.$mol_ambient({
$mol_page: $gd_kit_page,
$mol_link: $mol_link,
})
}
```
*/
export class $gd_kit_page extends $.$gd_kit_page {
protected kids = [] as $gd_kit_page[]
protected links = [] as $mol_link[]
@ $mol_memo.field
get $() {
super.$.$gd_kit_page_current?.kids.push(this)
return super.$.$mol_ambient({
$gd_kit_page_current: this
})
}
destructor() {
const parent = super.$.$gd_kit_page_current
if (! parent) return
parent.kids = parent.kids.filter(kid => kid !== this)
}
link_add(link: $mol_link) {
this.links.push(link)
}
link_delete(link: $mol_link) {
this.links = this.links.filter(obj => obj !== link)
}
@ $mol_mem
args_off() {
const result = {} as Record<string, null>
for (const kid of this.kids) Object.assign(result, kid.args_off())
for (const link of this.links) {
for (const key of Object.keys(link.arg())) {
result[key] = null
}
}
return result
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment