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

Refactor and group change handler data into an object #1063

Open
kitchoi opened this issue May 4, 2020 · 0 comments
Open

Refactor and group change handler data into an object #1063

kitchoi opened this issue May 4, 2020 · 0 comments

Comments

@kitchoi
Copy link
Contributor

kitchoi commented May 4, 2020

In the notifiers for observers, we have these pieces of information:

handler : callable(event)
The user's handler to receive the change event.
The event object is returned by the ``event_factory``.
If the handler is an instance method, then a weak reference is
created for the method. If the instance is garbage collected,
the notifier will be muted.
target : object
An object for defining the context of the notifier.
A weak reference is created for the target.
If the target is garbage collected, the notifier will be muted.
This target is typically an instance of ``HasTraits`` and will be
seen by the user as the "owner" of the change handler.
This is also used for distinguishing one notifier from another
notifier wrapping the same handler.

dispatcher : callable(handler, event)
A callable for dispatching the handler, e.g. on a different
thread or on a GUI event loop. ``event`` is the object
created by the event factory.

The handler, target and dispatcher are defined by the user at the time when observe is called (observe being the future replacement of on_trait_change). In other words, they don't change throughout the lifetime of the "observe" action and only the user has a say in what they should be.

They can therefore be grouped together, making it easy for them to be passed around and compared.

This refactoring will not affect the user facing API.

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

No branches or pull requests

1 participant