From e55e19d5e4115e4888da92f4e5e51e6e7410860b Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Sat, 14 May 2016 19:06:00 -0400 Subject: [PATCH] Add "on event ID BLOCK" support --- js/compiler/compiler.js | 3 +++ js/compiler/syndicate.ohm | 2 ++ js/src/actor.js | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/js/compiler/compiler.js b/js/compiler/compiler.js index 1e81092..30542b7 100644 --- a/js/compiler/compiler.js +++ b/js/compiler/compiler.js @@ -155,6 +155,9 @@ var modifiedSourceActions = { eventPattern.bindings, block.asES5); }, + FacetSituation_onEvent: function (_on, _event, id, block) { + return '\n.addOnEventHandler((function(' + id.asES5 + ') ' + block.asES5 + '))'; + }, FacetSituation_during: function(_during, pattern, facetBlock) { return buildOnEvent(false, 'asserted', diff --git a/js/compiler/syndicate.ohm b/js/compiler/syndicate.ohm index d9849c6..c5c00a6 100644 --- a/js/compiler/syndicate.ohm +++ b/js/compiler/syndicate.ohm @@ -45,6 +45,7 @@ Syndicate <: ES5 { FacetSituation = assert FacetPattern AssertWhenClause? #(sc) -- assert | on FacetEventPattern FunctionBodyBlock -- event + | on event identifier FunctionBodyBlock -- onEvent | during FacetPattern FacetBlock -- during AssertWhenClause = when "(" Expression ")" @@ -77,6 +78,7 @@ Syndicate <: ES5 { assertion = "assertion" ~identifierPart dataspace = "dataspace" ~identifierPart during = "during" ~identifierPart + event = "event" ~identifierPart ground = "ground" ~identifierPart message = "message" ~identifierPart metalevel = "metalevel" ~identifierPart diff --git a/js/src/actor.js b/js/src/actor.js index 889d203..2c14be9 100644 --- a/js/src/actor.js +++ b/js/src/actor.js @@ -93,6 +93,10 @@ Facet.prototype.addAssertion = function(assertionFn) { return this.addEndpoint(new Endpoint(assertionFn, function(e) {})); }; +Facet.prototype.addOnEventHandler = function(handler) { + return this.addEndpoint(new Endpoint(function () { return Patch.emptyPatch; }, handler)); +}; + Facet.prototype.onEvent = function(isTerminal, eventType, subscriptionFn, projectionFn, handlerFn) { var facet = this; switch (eventType) {