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

TBehavior event handlers not adding at the proper priority. #851

Closed
belisoful opened this issue Dec 25, 2022 · 5 comments
Closed

TBehavior event handlers not adding at the proper priority. #851

belisoful opened this issue Dec 25, 2022 · 5 comments

Comments

@belisoful
Copy link
Member

Basically, Behaviors should implement the new IPriorityProperty merge #849 at the IBaseBehavior level.

When the behavior is attached, the priority is already set on the behavior from being added to the list of owner behaviors. thus when the behavior is attached (and then events are added), the behavior events can be added at the behavior's priority. this is the expected behavior.

Much of the priority stuff in TBehaviorModule can be removed as well

@belisoful
Copy link
Member Author

This is needed for the new TAssetManager::publishAsset and TAsset files #835 as the new TAsset class depends on behaviors for all kinds of new augmentations, like blocking publishing of assets.

The various behaviors for modifying TAsset should have event priorities at the set priority in the list.

@belisoful
Copy link
Member Author

BTW, long ago Yii did away with the "enabled" flag on behaviors. I am very glad we kept it despite the complexity I am seeing now. The ability to enable and disable a behavior in the configuration without removing it entirely is very useful.

I see why they did it. It simplifies things, especially some core code in checking for enabled. For speed.

If this is something that people would like to see, removal of the Enabled flag in behaviors, let's converse.

@belisoful
Copy link
Member Author

belisoful commented Apr 23, 2023

I've been able to identify several strong points of the Yii implementation that should be accounted for and some weak points that are being upgraded.

@ctrlaltca The size of the change of behaviors is "big" and covers 3 active issues (and then some) but the size and scope of the upgrade to behaviors can't be helped. it stays in the scope of the core of behaviors (I/TBaseBehavior, I/TClassBehavior, and regular I/TBehavior interfaces and implementations [for 6 total classes]). With unit tests.

Yii has two features Prado doesn't have: Anonymous behaviors, and Lazy Loading of behaviors.

Prado has a few differences: Behaviors have priority. Events have priority. Object themselves have a "behaviors" enable flag, individual behaviors have an enable flag, (stateless) Class-wide behaviors, behaviors attach on Interfaces and Traits also (Yii only does objects with parents [and config?]), dynamic events, and global events.

New: Behavior events get their behaviors' priority. Behavior registered Events are optionally removed on disabling of behaviors or a behavior, by default they are removable on disable. Yii is active all the time. (In effect PRADO allows behaviors to be turned off in configuration without being totally removed). Multiple handlers can be placed on the same event without hacking the case of the event name. Class behaviors track all their owners by WeakReference. Behaviors are given a name property. Regular Behaviors link to owners by WeakRerefence properly. Yii only does hard links from behaviors to owners.

Behaviors will soon not directly linking to their owners. It leads to better object management without circular references or the need for circular reference processing by PHP.

About the 2 Yii features not in PRADO:

  • We could implement anonymous behaviors without names along the line with existing TMap, I think.
  • Lazy loading can be done in PRADO with another TComponent variable, and updating the system class wide behaviors, though is lazy loading the configure behaviors of an object really needed in 2023 of such performance and memory sizes of computers these days?

@belisoful
Copy link
Member Author

BTW, I've been working on the PHP Documentation. That is what is delaying this commit and merge. the documentation needs to be as good as the code for behaviors.

@belisoful
Copy link
Member Author

This has been needed for a very long time. It feels great to finally have this.

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

No branches or pull requests

1 participant