Add tests to demonstrate behaviour when mutating extension point directly #346
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR add tests to demonstrate the contradiction / challenge for solving #291.
In summary:
ExtensionPoint
is like a property. Its value is recomputed on every access of the attribute.x_items
listenerx_items
is misleading.Details:
When someone defines an ExtensionPoint in their class like this:
One can listen to changes to
x_items
, like this:This makes developers believe that
x
is like a persisted list and they can listen to its mutation.But that is in fact not true. The value of the extension point is computed every time when the attribute is accessed. It is more like a Property. For it is ephemeral, one cannot listen to the mutation on the list that is refreshed on every access.
In fact, when one listens to
x_items
in the context of extension points, what they are listening to is changes from the contributors of that extension point, and what they want is the specific details on what have been removed or added to the extension point. Envisage could well have called thatx_contribution_changed
, orx_whatever_event
. The naming ofx_items
is unfortunate as it clashes with the meaning of mutating a persisted list in on_trait_change mini-language.