Add "on event ID BLOCK" support

This commit is contained in:
Tony Garnock-Jones 2016-05-14 19:06:00 -04:00
parent 0561a02e78
commit e55e19d5e4
3 changed files with 9 additions and 0 deletions

View File

@ -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',

View File

@ -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<withIn> ")"
@ -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

View File

@ -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) {