Skip to content

Set hook #600

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Set hook #600

wants to merge 2 commits into from

Conversation

s-cork
Copy link
Member

@s-cork s-cork commented Mar 27, 2025

this PR is an idea for a set hook

for custom components we already have descriptors on the form template
but if we want to do something when we set a property we end up recreating descriptors
what if we could just tap into the existing descriptors on the template

this PR shows that idea

#Before

class C(CTemplate):
    @property
    def text(self):
        return getattr(self, "_text", None)
        
    @text.setter
    def text(self, value):
        self._text = value
        self._some_node.textContent = value

# After

class C(CTemplate):
    @set_hook
    def on_set_text(self):
        self._some_node.textContent = self.text

Is it worth it?
Maybe

@meatballs
Copy link
Member

I like how much code that removes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants