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

Fix behavior in removeObserver. #349

Merged
merged 3 commits into from
Mar 11, 2021
Merged

Fix behavior in removeObserver. #349

merged 3 commits into from
Mar 11, 2021

Conversation

typesupply
Copy link
Member

The change I made to allow None to indicate "please remove everything that observer is watching in observable" had a logic flaw.

  • In addObserver, notification=None means "send every notification to this observer for this observable".
  • In removeObserver, notification means "remove every registered notification from this observable for this observer".

Those seem alike, but this example shows my mistake:

er = This()
able = That()

able.addObserver(observer=er, notification=None, method="anyNotificationHappened")
able.addObserver(observer=er, notification="specific", method="specificNotificationHappened")

able.removeObserver(observer=er, notification=None)

The notification=None has two conflicting meanings:

  1. Remove the notification that will call method er.anyNotificationHappened.
  2. Remove all observations for er.
    • er.anyNotificationHappened
    • er.specificNotificationHappened

Being able to vigorously remove observations without knowing specific notifications is useful, but the previous behavior is more important. So, I'm introducing an "all" option for notification to provide the new functionality without changing the old.

The change I made to allow `None` to indicate "please remove everything that observer is watching in observable" had a logic flaw.

- In `addObserver`, `notification=None` means "send every notification to this observer for this observable".
- In `removeObserver`, `notification` means "remove every registered notification from this observable for this observer".

Those seem alike, but this example shows my mistake:

```python
er = This()
able = That()

able.addObserver(observer=er, notification=None, method="anyNotificationHappened")
able.addObserver(observer=er, notification="specific", method="specificNotificationHappened")

able.removeObserver(observer=er, notification=None)
```

The `notification=None` has two conflicting meanings:

1. Remove the notification that will call method `er.anyNotificationHappened`.
2. Remove all observations for er.
    - `er.anyNotificationHappened`
    - `er.specificNotificationHappened`

Being able to vigorously remove observations without knowing specific notifications is useful, but the previous behavior is more important. So, I'm introducing an "all" option for `notification` to provide the new functionality without changing the old.
@typesupply
Copy link
Member Author

Ugh. Failed a test. Working on it.

…ometimes things (cough tests cough) remove things that haven't been registered.
@typesupply
Copy link
Member Author

Failing tests fixed.

@typemytype typemytype merged commit 9abb77a into master Mar 11, 2021
@typemytype typemytype deleted the notification-fix branch March 11, 2021 22:33
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