nucleic / enaml

Declarative User Interfaces for Python
http://enaml.readthedocs.io/en/latest/
Other
1.53k stars 130 forks source link

Add new declarative @observe which ignores 'create' events by default #479

Closed frmdstryr closed 2 years ago

frmdstryr commented 2 years ago

In order to avoid unnecessary calls to to _update_proxy (which by default only handles the update event type anyways), this change adds a new observe decorator in enaml.core.declarative that updates the default change_types flag to ignore create events. The widget declarations were updated to use the new import instead of the one from atom.api.

The static observer added by the declarative metaclass will also ignore created events.

Any 3rd-party code using the original atom.api for custom members will be unchanged unless it relied on a create event from a superclass member.

If someone needs the create event, either use the observe decorator from the atom.api or pass in the change_types flags for the needed. If the member had @observe on a super class, you can re-bind it with new flags to change the events triggerd.

MatthieuDartiailh commented 2 years ago

This looks really nice !

MatthieuDartiailh commented 2 years ago

The 3.7 fails are expected we are dropping support for it bit the CI update is a pending PR.

MatthieuDartiailh commented 2 years ago

I managed to fix the CIs though so could you rebase so that at least this is green ?

codecov-commenter commented 2 years ago

Codecov Report

Merging #479 (57c5121) into main (ebcfec8) will decrease coverage by 0.16%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #479      +/-   ##
==========================================
- Coverage   73.23%   73.06%   -0.17%     
==========================================
  Files         316      316              
  Lines       24123    24125       +2     
  Branches       55       55              
==========================================
- Hits        17666    17628      -38     
- Misses       6457     6497      +40     
MatthieuDartiailh commented 2 years ago

Actually for the docs in their current state I do not see where to add the information. It is a bit advanced for the getting started. it may have to wait for a doc overhaul...

MatthieuDartiailh commented 2 years ago

The coverage change is somewhat expected since we generate less event at start-up and the tests do not exert the widget beyond this point for most of them.

MatthieuDartiailh commented 2 years ago

@frmdstryr let me know your opinion regarding the documentation but with an entry in the release notes I believe this is good to go.

frmdstryr commented 2 years ago

Maybe there should be something in the Architecture Reference?

MatthieuDartiailh commented 2 years ago

I think so, too, but this is currently empty. If you are inspired, feel free to get the section started.