Created
December 1, 2023 08:55
-
-
Save zerkalica/147d50b75642c1099283f4d1178eb63c to your computer and use it in GitHub Desktop.
hierarchical off links in mol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace $.$$ { | |
export class $gd_kit_link extends $.$gd_kit_link { | |
make_uri(args: ReturnType<typeof this.arg>) { | |
const dict = this.$.$mol_state_arg.dict() | |
const href_args = { ...dict, ...args } | |
return this.$.$mol_state_arg.make_link( href_args ) | |
} | |
@ $mol_mem | |
uri() { | |
return this.make_uri(this.arg()) | |
} | |
@ $mol_mem | |
current() { | |
const current = super.current() | |
if (current) this.$.$gd_kit_page_current?.link_add(this) | |
else this.$.$gd_kit_page_current?.link_delete(this) | |
return current | |
} | |
override destructor() { | |
this.$.$gd_kit_page_current?.link_delete(this) | |
} | |
arg_off_self() { | |
const result = { ... this.arg() } | |
for (let key in result) result[key] = null | |
return result | |
} | |
arg_off() { | |
return { | |
...this.$.$gd_kit_page_current?.args_off(), | |
...this.arg_off_self() | |
} | |
} | |
@ $mol_mem | |
uri_off() { | |
return this.make_uri(this.arg_off()) | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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