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.

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



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.



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
Ortus Solutions, Corp

ColdBox Platform:
Linked In:
IECFUG Manager: