Day 11 – Global Block

Goal: demonstrate using global block in ruleset

ruleset a60x477 {
  meta {
    name "global-domain-test"
    description <<
    author "Mike Grace"
    logging on

  global {
    // pre block type stuff
    currentDomain = page:url("domain");
    a = "a";
    testArray = [1,2,3,4];
    superData = {
      "location":"unknown : )"

    // special global block stuff
    css <<
      h1 {
        font-size: 50px;
    emit <|
    dataset public_timeline <-  "";
    datasource tsearch <- "";

  rule tester_rule is active {
    select when pageview ".*"
      notify("currentDomain",currentDomain) with sticky = true;
      notify("a",a) with sticky = true;
      notify("testArray",testArray[0]) with sticky = true;

  rule second_tester {
    select when pageview ".*"
    pre {
      kynetxTweets = datasource:tsearch("?q=kynetx");
      location = superData.pick("$.location");
      stuff =<<
      timeline = public_timeline;
      append("body", stuff);
      emit <|
        console.log("public twitter timeline");
        console.log("kynetx tweets");
  • 11-33 global block
  • 13 gets the domain from the event request
  • 15 sets up basic array
  • 16 sets up basic hash
  • 12-20 all stuff that can be done in a pre block of a rule
  • 22-32 stuff that can be done in a global block but not a pre block
  • 23-27 emitted CSS block can only be in the global block (*there are other ways of doing CSS)
  • 28-30 JS emit block can be done as an action in the action block
  • 31 dataset is setup and queried but can’t be accessed raw from within the action block unless it has been accessed in the pre block of a rule -> see line 54
  • 32 datasource query setup but not executed

App run on with bookmarklet

Browser console output on after running app with bookmarklet

  • The global block is executed for each ruleset evaluation so be careful what you put in the global block
  • I think of the global block as being a pre block with special powers and all the rules in my ruleset have access to the global block variables

Get the bookmarklet to try it out yourself!

Gratuitous day 11 crazy face

This entry was posted in Kynetx and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s