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!)

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Comments