Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be less willy-nilly about re-using components #6

Merged
merged 1 commit into from
Jun 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions puepy/core.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import binascii
import hashlib

from .exceptions import ElementNotInDom, PropsError, PageError
from .reactivity import ReactiveDict, Stateful
from .util import (
mixed_to_underscores,
merge_classes,
jsobj,
_extract_event_handlers,
patch_dom_element,
)

from .runtime import (
add_event_listener,
remove_event_listener,
Expand All @@ -17,6 +12,12 @@
setTimeout,
CustomEvent,
)
from .util import (
mixed_to_underscores,
merge_classes,
_extract_event_handlers,
patch_dom_element,
)


class Prop:
Expand Down Expand Up @@ -705,12 +706,15 @@ def generate_tag(self, tag_name, *children, **kwargs):
raise Exception("t.generate_tag called without a context")

# Determine ref value
ref_part = f"__{parent.ref}.{tag_name}{len(parent.children) + 1}"
ref_part = f"__{parent.ref}.{tag_name}{len(parent.children) + 1}_" + binascii.hexlify(
hashlib.sha256(str(kwargs).encode()).digest()
)[:8].decode("utf8")

ref = kwargs.pop("ref", ref_part)

if ref and origin and ref in origin._refs_pending_removal:
element = origin._refs_pending_removal.pop(ref)
element: Tag = origin._refs_pending_removal.pop(ref)

assert element.origin == origin
element._configure(kwargs)
element.children = []
Expand Down
Loading