Skip to main content

Attributes with superpowers

Project description

reacttrs

Reactive attributes extracted out from Textual.

from reacttrs import reactive


class Foo:

    name = reactive("Paul")
    age = reactive(33)
    birth = reactive(1990)

    def watch_name(self, old, new):
        print(f"{old=}, {new=}")

    def validate_name(self, name):
        if name == "John":
            print("Hey John!")
        return name

    def compute_age(self) -> int:
        age = 2023 - self.birth
        print(f"{age=}")
        return age

foo = Foo()
foo.name = "John"
foo.name = "Steve"

foo.age
foo.birth = 1991
foo.age

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

reacttrs-0.1.4.tar.gz (4.2 kB view hashes)

Uploaded Source

Built Distribution

reacttrs-0.1.4-py3-none-any.whl (5.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page