Model-Glue 3 - Custom Event Types - Want that in XML?

After my last post on custom event types in Model-Glue 3, the reaction was pretty much universal. Nice - but why can't we define these guys in XML?

As of about an hour or so ago, Joe checked into the MG3 Subversion repo an update that now allows you to do custom event types in XML, and frankly, it kicks butt. To define a custom event type, you create a new section of your ModelGlue.xml file named event-types. Here is an example:

<event-types>
   <event-type name="templatedPage">
      <after>
         <results>
            <result do="template.main" />
         </results>
      </after>
   </event-type>
</event-types>

In general these follow the same formats as events, but they are separated into a before and after section. You would put broadcasts in the before block. Here is an example Joe created showing a security custom event type:

<event-type name="securedPage">
   <before>
      <broadcasts>
         <message name="doSecurityCheck" />
      </broadcasts>
   </before>
</event-type>

Using the custom event type hasn't changed. You simply provide the name:

<event-handler name="page.index" type="templatedPage">

And of course you can use multiple custom event types:

<event-handler name="page.index" type="securedPage,templatedPage">

Can I get an "Amen" from the Model-Glue crowd?? (Thanks Joe!)

Comments

Hey!

That looks HOT!

I'm updating from SVN as we speak!

DW
# Posted By Dan Wilson | 6/11/08 1:00 PM
I'm not sure how that much code to simply let it know about a custom even "kicks butt". Then again, I'm a bit old fashioned and don't think XML should be used for anything other than actual data.
# Posted By Allen | 6/11/08 5:42 PM
@Allen - In the past, you had to redirect to a display template, broadcast security on every secured method, etc, so this actually cuts down on a lot of code. I'm surprised you think the XML up there is a lot. The display template is 8 lines of code - used once.
# Posted By Raymond Camden | 6/11/08 8:40 PM
sweet stuff, thanks for the info Ray
# Posted By Chris H | 6/12/08 2:44 AM
makes by day
# Posted By Sameer Gupta | 6/12/08 7:43 AM
Excellent.
# Posted By Jeremy Prevost | 6/12/08 12:41 PM