Welcome Guest, Not a member yet? Register   Sign In
Khaos :: KhEvent
#11

[eluser]Majd Taby[/eluser]
I'm thinking this could be great for CodeExtinguisher, it makes it really easy to make things happen on insert, update, delete etc. Right now I have basic callbacks, but this is much better.
#12

[eluser]Majd Taby[/eluser]
is it possible to have multiple classes handle the same event?

i.e. can I have two files in khaos/plugins/ which both define a 'onUserLogin', and both which get called automatically when the onUserLogin event is triggered?
#13

[eluser]Neophyte[/eluser]
[quote author="jTaby" date="1202943239"]is it possible to have multiple classes handle the same event?

i.e. can I have two files in khaos/plugins/ which both define a 'onUserLogin', and both which get called automatically when the onUserLogin event is triggered?[/quote]

Yup.

The disptacher keeps track of everything so when you trigger an event it knows all the classes/plugins which have a method to handle that event and it calls each of them (passing any optional args you want and then returns an indexed array of the responses received from each of the plugins which responded)
#14

[eluser]Majd Taby[/eluser]
Ok, my next question was why it returns an indexed array...i see now..this is fantastic neophyte...it'll be in the next version of codeExtinguisher Smile
#15

[eluser]WolfgangA[/eluser]
@neophyte
Is your event system based on Observer Design Pattern?
#16

[eluser]Neophyte[/eluser]
[quote author="WolfgangA" date="1203037830"]@neophyte
Is your event system based on Observer Design Pattern?[/quote]

yes
#17

[eluser]zeroeighteen[/eluser]
[quote author="Neophyte" date="1202947458"][quote author="jTaby" date="1202943239"]is it possible to have multiple classes handle the same event?

i.e. can I have two files in khaos/plugins/ which both define a 'onUserLogin', and both which get called automatically when the onUserLogin event is triggered?[/quote]

Yup.

The disptacher keeps track of everything so when you trigger an event it knows all the classes/plugins which have a method to handle that event and it calls each of them (passing any optional args you want and then returns an indexed array of the responses received from each of the plugins which responded)[/quote]

Is there a way to determine which class gets triggered first? If i'm worried about the order it triggers, would it be better for one class' trigger to just make calls to all the other classes? i think this event system is a great idea, because the application i'm working on has elements of being state based ... but at the same time, having a chain of events trigger one after another feels sort of inefficient.

thanks
#18

[eluser]Neophyte[/eluser]
If you have multiple plugins all listening on the same event and need to adjust the order in which they are triggered then you just need to adjust the order in which they appear in the config array.

Quote:would it be better for one class’ trigger to just make calls to all the other classes

This is essentially what is happening, the dispatcher holds an array of all the observers (plugins in this case) so when you trigger an event the dispatcher iterates over the observers and informs each one about the event and then returns an indexed array of results to you.

eg. if you had 5 plugins the dispatcher would iterate 5 times informing each one of the details of the event and append any results to the results array before returning the info to you, it's all pretty fast stuff but i'll accept any optimisation suggestions, in the Event.php file the lines of note are 292-340 and 370-388.
#19

[eluser]Monotoba[/eluser]
Hi,

I am quite excited to read this post as will be quite interested in the results. I like event driven environments. They can make adding new functionality much easier.

About 5 years ago I wrote a php framework for internal use in a company I was contracted with at that time. It was an event driven framework that allowed each event to register a view with the view system. A call to a single "show()" method at the end of the cycle presented all subviews within a master template view. Basically each view was a div and the template view was created partly from predefined templates (for header and footer) and partly from code. Each veiw was given a handle and any subviews could use the a parent handle to specify they were subviews of the parent. They could also get the handle of any ancestor to become a subview of that ancestor. The whole thing ended up quit complex but the power and ease of creating a new module that just simple worked was awsume!

Events were taken from the url segments and each module's response was bubbled back up the event ladder so parents could respond if needed. The whole thing kinda resibled windows 98/XP API mostly becuase of my days writing games and desktop apps.

Will your system provide any functionality for parents to respond to child responses? Will allow each child to generate a view if needed? If so, how will you handle subviews?
#20

[eluser]Avatar[/eluser]
Wow, this sounds great. I will check it out. Thank you.




Theme © iAndrew 2016 - Forum software by © MyBB