Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

As the rule in the previous section shows, rules Rules are conditional actions. The action can be anything appropriate to the domain. For a browser extension endpoint, actions usually modify the DOM and consequently affect how the page is rendered in the browser. (The DOM, short for Document Object Model, is the data structure representing the page that the browser maintains to render it. Changing the DOM dynamically changes what the user sees displayed in the browser.) For an email endpoint, the actions are appropriate to managing email.Actions usually cause some effect outside the pico. For example, an action might fire off an HTTP POST or send a message to another pico. 

Event expressions can be used to specify complex event patterns. A rule is selected when the eventex in the rule's select statement matches events in the rule set's event stream.

...

Event expressions can use filters to further distinguish one event from another. For example, the following eventex matches pageview events where the URL has a particular format:

Code Block
languagejavascript
themeConfluencelanguagejavascript
rule url_in_filter { 
  select when pageview where url.match(#/archives/\d{4}/#)
  notify(...)
}

Suppose, instead, that you had written the URL filter as a condition in a rule using the event attribute function:

Code Block
languagejavascript
themeConfluencelanguagejavascript
rule url_in_condition { 
  select when pageview 
  if event:attr("url").match(#/archives/\d{4}/#) then 
    notify(...) 
}

...

Consider the following select statement:

Code Block
languagejavascript
themeConfluencelanguagejavascript
select when repeat(5, withdrawal where amount.match(#$(\d+\.\d\d)#) && amount > 100) max(m) 

Expressed in KRL, this concept would be more verbose and difficult to understand. 

Rule conditions have the advantage of being able to take other data, aside from the events and attributes, into consideration when determining whether a rule should fire. KRL makes it easy to access data from cloud-based APIs. In addition, a number of intrinsic functions and libraries offer additional data to a KRL rule set. Consequently, conditions are important for making decisions based on user context because there's more of it available to conditions than there is in an eventex, regardless of sophistication.