Last Event

I found the below thread in the old forum and I am trying to do the
same thing. I am moving some functions between various handlers to
better organize some code that I inherited and would like to know what
previous event is calling a function.

http://forums.coldbox.org/index.cfm?event=ehMessages.dspMessages&threadid=0561A0E5-123F-6116-42AAF560F3DC61DD

This thread is from 2007 and I hoping something was built that I can
take advantage of.

Thanks.

Jonathan

I don't know of anything that's been built, but frankly it's so simple I don't know if it warrants much in the way of an organized project. Just put a line of code in your request end handler to pull the current event out and place it in session in a previousEvent variable. (much like the thread you linked to shows).

Then, anywhere you want to know what the previous event was, check for the existence of that variable and use it.

Thanks!

~Brad

I am guessing you mean when doing event chaining via runEvent().

First, let me make something clear. Chaining events with runEVent() is possible but not desired unless you are doing viewlets or self sustainable events. It can lead to messy code bouncing. A better approach is using event driven programming via interceptors.

Anyways, if you want to keep a stack of events that are being executed you can easily build an interceptor that intercepts at “postEvent” that will add to your local executing stack. Something ike this:

function postEvent(event, interceptData){
var prc = event.getCollection(private=true);
var cEvent = arguments.interceptData.processedEvent;

if( not structKeyExists(prc,“executedEvents”) ){
prc.executedEvents = [];
}
arrayAppend( prc.executedEvents, cEvent);
}

Just like that you create a stack on the private collection of all executing events, the executing event sees the last one and all previous ones, once it completes, the postEvent adds the last one and so forth.

Luis F. Majano
President
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano