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

feat: Nested events [wip] #169

Closed
wants to merge 15 commits into from
Closed

Conversation

tlambert03
Copy link
Member

@tlambert03 tlambert03 commented Feb 12, 2023

this would add support for detected events from nested children in a tree-like evented-dataclass structure. still wip

In [1]: from psygnal._evented_decorator import connect_child_events

In [2]: from dataclasses import dataclass, field

In [3]: from psygnal import evented

In [4]:     @evented
   ...:     @dataclass
   ...:     class Foo:
   ...:         x: int = 1
   ...:
   ...:     @evented
   ...:     @dataclass
   ...:     class Bar:
   ...:         y: int = 2
   ...:         foo: Foo = field(default_factory=Foo)
   ...:

In [5]: bar = Bar()

In [6]: bar.events.connect(print)
Out[6]: <function print at 0x10b631a20>

In [7]: bar.foo.x = 8

In [8]: connect_child_events(bar)

In [9]: bar.foo.x = 12
EmissionInfo(
    signal=<SignalGroup 'FooSignalGroup' with 1 signal on Foo(x=12)>,
    args=(
        EmissionInfo(
            signal=<SignalInstance 'x' on <SignalGroup 'FooSignalGroup' with 1 signal on
Foo(x=12)>>,
            args=(12,),
            attr_name=None
        ),
    ),
    attr_name='foo'
)

@tlambert03
Copy link
Member Author

closing this and picking it up in #298

@tlambert03 tlambert03 closed this Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant