Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: add engine compatibility note

Explicit events are raised in the rule postlude with a raise statement. You can raise explicit events from a postlude like so:

Code Block
languagejavascript
themeConfluencelanguagejavascript
raise <domain> event <expr> [for <expr>] [with <modifier_clause> | attributes <expr>] 

...

The modifier clause allows the developer to add event parameters to the explicit event. The right side of the individual bindings in the with clause can be any KRL expression. The modifier clause takes the following form:

Code Block
languagejavascript
themeConfluencelanguagejavascript
with <var> = <expr> [and <var> = <expr>]* 

...

The following example illustrates this

Code Block
languagejavascript
themeConfluencelanguagejavascript
raise explicit event 'foo' 
  with a = "hello"
   and b = 4 + x;
Info
titleEngine Compatibility

In the node pico engine, the modifier clause has this form (note, no "and"):

with <var> = <expr> [ <var> = <expr> ]*

making the example

raise explicit event 'foo'

with a = "hello"

b = 4 + x

Attributes Clause

The attributes clause also allows the developer to add event attributes to the explicit event. The expression that follows the attributes key word must evaluate to a map. The keys and values in the map will be used as event attributes. This is particularly useful when you want to pass thru all, or most, of the attributes that the current rule received:

Code Block
language
languagejavascript
themeConfluencejavascript
raise explicit event 'foo' 
  attributes event:attrs()

...

In the Sky Event API, explicit events will be raised to any ruleset that an entity has installed unless a for clause is present. You can specify the current ruleset using the meta:rid() functions from the meta library.  Normally the API is determined by what API was used to raise the event that caused processing to commence. You can ensure that the behavior of explicit events will follow the Sky API behavior by specifying that the Sky API be used as follows:

Code Block
language
languagejavascript
themeConfluencejavascript
raise explicit event 'foo' 
  with a = "hello"
   and b = 4 + x
   and _api = "sky";

...

Like any other postlude statement, explicit events can be guarded:

Code Block
languagejavascript
themeConfluencelanguagejavascript
raise explicit event 'foo'
  with a = "hello"
   and b = 4 + x
 if (flipper eq "two");

...