Browse Source

Make AxonInterest more generic.

Herbert Vojčík 6 years ago
parent
commit
09fc7d8192
2 changed files with 240 additions and 51 deletions
  1. 187 34
      src/Axxord.js
  2. 53 17
      src/Axxord.st

+ 187 - 34
src/Axxord.js

@@ -514,8 +514,8 @@ $1=$recv(each)._isFlagged();
 if($core.assert($1)){
 $recv(each)._run();
 }
-$2=$recv(each)._isEnabled();
-if(!$core.assert($2)){
+$2=$recv(each)._isClosed();
+if($core.assert($2)){
 needsClean=true;
 return needsClean;
 }
@@ -546,10 +546,10 @@ return self;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "run\x0a\x09[\x0a\x09\x09| needsClean |\x0a\x09    needsClean := false.\x0a\x09\x09self do: [ :each |\x0a\x09\x09\x09each isFlagged ifTrue: [ each run ].\x0a\x09        each isEnabled ifFalse: [ needsClean := true ]\x0a\x09\x09].\x0a    \x09needsClean ifTrue: [ self clean ]\x0a\x09] on: Error do: [ self dirty: true ]",
+source: "run\x0a\x09[\x0a\x09\x09| needsClean |\x0a\x09    needsClean := false.\x0a\x09\x09self do: [ :each |\x0a\x09\x09\x09each isFlagged ifTrue: [ each run ].\x0a\x09        each isClosed ifTrue: [ needsClean := true ]\x0a\x09\x09].\x0a    \x09needsClean ifTrue: [ self clean ]\x0a\x09] on: Error do: [ self dirty: true ]",
 referencedClasses: ["Error"],
 //>>excludeEnd("ide");
-messageSends: ["on:do:", "do:", "ifTrue:", "isFlagged", "run", "ifFalse:", "isEnabled", "clean", "dirty:"]
+messageSends: ["on:do:", "do:", "ifTrue:", "isFlagged", "run", "isClosed", "clean", "dirty:"]
 }),
 $globals.Axon);
 
@@ -649,11 +649,11 @@ var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-$self["@queue"]=$recv($self["@queue"])._select_((function(each){
+$self["@queue"]=$recv($self["@queue"])._reject_((function(each){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx2) {
 //>>excludeEnd("ctx");
-return $recv(each)._isEnabled();
+return $recv(each)._isClosed();
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
 //>>excludeEnd("ctx");
@@ -665,10 +665,10 @@ return self;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "clean\x0a\x09queue := queue select: [ :each | each isEnabled ]",
+source: "clean\x0a\x09queue := queue reject: [ :each | each isClosed ]",
 referencedClasses: [],
 //>>excludeEnd("ide");
-messageSends: ["select:", "isEnabled"]
+messageSends: ["reject:", "isClosed"]
 }),
 $globals.SimpleAxon);
 
@@ -730,7 +730,7 @@ $globals.SimpleAxon);
 
 
 
-$core.addClass("AxonInterest", $globals.Object, ["aspect", "actionBlock", "flagged"], "Axxord");
+$core.addClass("AxonInterest", $globals.Object, ["flagged"], "Axxord");
 $core.addMethod(
 $core.method({
 selector: "accepts:",
@@ -757,21 +757,49 @@ $globals.AxonInterest);
 
 $core.addMethod(
 $core.method({
-selector: "aspect:block:",
-protocol: "accessing",
-fn: function (anAspect,aBlock){
+selector: "close",
+protocol: "action",
+fn: function (){
 var self=this,$self=this;
-$self["@aspect"]=anAspect;
-$self["@actionBlock"]=aBlock;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+$self._subclassResponsibility();
 return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"close",{},$globals.AxonInterest)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "close\x0a\x09self subclassResponsibility",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["subclassResponsibility"]
+}),
+$globals.AxonInterest);
 
+$core.addMethod(
+$core.method({
+selector: "enact",
+protocol: "action",
+fn: function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+$self._subclassResponsibility();
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"enact",{},$globals.AxonInterest)});
+//>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
-args: ["anAspect", "aBlock"],
-source: "aspect: anAspect block: aBlock\x0a\x09aspect := anAspect.\x0a    actionBlock := aBlock",
+args: [],
+source: "enact\x0a\x09self subclassResponsibility",
 referencedClasses: [],
 //>>excludeEnd("ide");
-messageSends: []
+messageSends: ["subclassResponsibility"]
 }),
 $globals.AxonInterest);
 
@@ -811,8 +839,6 @@ $ctx1.supercall = true,
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.supercall = false;
 //>>excludeEnd("ctx");;
-$self["@aspect"]=nil;
-$self["@actionBlock"]=nil;
 $self["@flagged"]=false;
 return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
@@ -821,7 +847,7 @@ return self;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "initialize\x0a\x09super initialize.\x0a    aspect := nil.\x0a    actionBlock := nil.\x0a    flagged := false.",
+source: "initialize\x0a\x09super initialize.\x0a    flagged := false.",
 referencedClasses: [],
 //>>excludeEnd("ide");
 messageSends: ["initialize"]
@@ -830,24 +856,25 @@ $globals.AxonInterest);
 
 $core.addMethod(
 $core.method({
-selector: "isEnabled",
+selector: "isClosed",
 protocol: "testing",
 fn: function (){
 var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-return $recv($self["@actionBlock"])._notNil();
+$self._subclassResponsibility();
+return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"isEnabled",{},$globals.AxonInterest)});
+}, function($ctx1) {$ctx1.fill(self,"isClosed",{},$globals.AxonInterest)});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "isEnabled\x0a\x09^actionBlock notNil",
+source: "isClosed\x0a\x09self subclassResponsibility",
 referencedClasses: [],
 //>>excludeEnd("ide");
-messageSends: ["notNil"]
+messageSends: ["subclassResponsibility"]
 }),
 $globals.AxonInterest);
 
@@ -884,14 +911,18 @@ return $core.withContext(function($ctx2) {
 //>>excludeEnd("ctx");
 $self["@flagged"]=false;
 $self["@flagged"];
-return $recv($self["@actionBlock"])._value();
+return $self._enact();
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
 //>>excludeEnd("ctx");
 }))._on_do_($globals.AxonOff,(function(){
-$self["@actionBlock"]=nil;
-return $self["@actionBlock"];
-
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+return $self._close();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
+//>>excludeEnd("ctx");
 }));
 return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
@@ -900,16 +931,138 @@ return self;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "run\x0a\x09[ flagged := false. actionBlock value ]\x0a    on: AxonOff do: [ actionBlock := nil ]",
+source: "run\x0a\x09[ flagged := false. self enact ]\x0a    on: AxonOff do: [ self close ]",
 referencedClasses: ["AxonOff"],
 //>>excludeEnd("ide");
-messageSends: ["on:do:", "value"]
+messageSends: ["on:do:", "enact", "close"]
 }),
 $globals.AxonInterest);
 
 
 
-$core.addClass("InterestedInEqual", $globals.AxonInterest, [], "Axxord");
+$core.addClass("ConstantAspectPluggableEnactInterest", $globals.AxonInterest, ["aspect", "actionBlock"], "Axxord");
+$core.addMethod(
+$core.method({
+selector: "aspect:block:",
+protocol: "accessing",
+fn: function (anAspect,aBlock){
+var self=this,$self=this;
+$self["@aspect"]=anAspect;
+$self["@actionBlock"]=aBlock;
+return self;
+
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["anAspect", "aBlock"],
+source: "aspect: anAspect block: aBlock\x0a\x09aspect := anAspect.\x0a    actionBlock := aBlock",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: []
+}),
+$globals.ConstantAspectPluggableEnactInterest);
+
+$core.addMethod(
+$core.method({
+selector: "close",
+protocol: "action",
+fn: function (){
+var self=this,$self=this;
+$self["@actionBlock"]=nil;
+return self;
+
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "close\x0a\x09actionBlock := nil",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: []
+}),
+$globals.ConstantAspectPluggableEnactInterest);
+
+$core.addMethod(
+$core.method({
+selector: "enact",
+protocol: "action",
+fn: function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+$recv($self["@actionBlock"])._value();
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"enact",{},$globals.ConstantAspectPluggableEnactInterest)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "enact\x0a\x09actionBlock value",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["value"]
+}),
+$globals.ConstantAspectPluggableEnactInterest);
+
+$core.addMethod(
+$core.method({
+selector: "initialize",
+protocol: "initialization",
+fn: function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+(
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.supercall = true,
+//>>excludeEnd("ctx");
+($globals.ConstantAspectPluggableEnactInterest.superclass||$boot.nilAsClass).fn.prototype._initialize.apply($self, []));
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.supercall = false;
+//>>excludeEnd("ctx");;
+$self["@aspect"]=nil;
+$self["@actionBlock"]=nil;
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.ConstantAspectPluggableEnactInterest)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "initialize\x0a\x09super initialize.\x0a    aspect := nil.\x0a    actionBlock := nil.",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["initialize"]
+}),
+$globals.ConstantAspectPluggableEnactInterest);
+
+$core.addMethod(
+$core.method({
+selector: "isClosed",
+protocol: "testing",
+fn: function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return $recv($self["@actionBlock"])._isNil();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"isClosed",{},$globals.ConstantAspectPluggableEnactInterest)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "isClosed\x0a\x09^actionBlock isNil",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["isNil"]
+}),
+$globals.ConstantAspectPluggableEnactInterest);
+
+
+
+$core.addClass("InterestedInEqual", $globals.ConstantAspectPluggableEnactInterest, [], "Axxord");
 $core.addMethod(
 $core.method({
 selector: "accepts:",
@@ -935,7 +1088,7 @@ $globals.InterestedInEqual);
 
 
 
-$core.addClass("InterestedThruAxes", $globals.AxonInterest, [], "Axxord");
+$core.addClass("InterestedThruAxes", $globals.ConstantAspectPluggableEnactInterest, [], "Axxord");
 $core.addMethod(
 $core.method({
 selector: "accepts:",
@@ -987,7 +1140,7 @@ $globals.InterestedThruAxes);
 
 
 
-$core.addClass("InterestedUpToAxes", $globals.AxonInterest, [], "Axxord");
+$core.addClass("InterestedUpToAxes", $globals.ConstantAspectPluggableEnactInterest, [], "Axxord");
 $core.addMethod(
 $core.method({
 selector: "accepts:",

+ 53 - 17
src/Axxord.st

@@ -112,7 +112,7 @@ run
 	    needsClean := false.
 		self do: [ :each |
 			each isFlagged ifTrue: [ each run ].
-	        each isEnabled ifFalse: [ needsClean := true ]
+	        each isClosed ifTrue: [ needsClean := true ]
 		].
     	needsClean ifTrue: [ self clean ]
 	] on: Error do: [ self dirty: true ]
@@ -157,7 +157,7 @@ add: aSubscription
 !SimpleAxon methodsFor: 'bookkeeping'!
 
 clean
-	queue := queue select: [ :each | each isEnabled ]
+	queue := queue reject: [ :each | each isClosed ]
 ! !
 
 !SimpleAxon methodsFor: 'enumeration'!
@@ -174,33 +174,34 @@ initialize
 ! !
 
 Object subclass: #AxonInterest
-	instanceVariableNames: 'aspect actionBlock flagged'
+	instanceVariableNames: 'flagged'
 	package: 'Axxord'!
 
 !AxonInterest methodsFor: 'accessing'!
 
-aspect: anAspect block: aBlock
-	aspect := anAspect.
-    actionBlock := aBlock
-!
-
 flag
 	flagged := true
 ! !
 
 !AxonInterest methodsFor: 'action'!
 
+close
+	self subclassResponsibility
+!
+
+enact
+	self subclassResponsibility
+!
+
 run
-	[ flagged := false. actionBlock value ]
-    on: AxonOff do: [ actionBlock := nil ]
+	[ flagged := false. self enact ]
+    on: AxonOff do: [ self close ]
 ! !
 
 !AxonInterest methodsFor: 'initialization'!
 
 initialize
 	super initialize.
-    aspect := nil.
-    actionBlock := nil.
     flagged := false.
 ! !
 
@@ -211,15 +212,50 @@ accepts: anAspect
     self subclassResponsibility
 !
 
-isEnabled
-	^actionBlock notNil
+isClosed
+	self subclassResponsibility
 !
 
 isFlagged
 	^flagged
 ! !
 
-AxonInterest subclass: #InterestedInEqual
+AxonInterest subclass: #ConstantAspectPluggableEnactInterest
+	instanceVariableNames: 'aspect actionBlock'
+	package: 'Axxord'!
+
+!ConstantAspectPluggableEnactInterest methodsFor: 'accessing'!
+
+aspect: anAspect block: aBlock
+	aspect := anAspect.
+    actionBlock := aBlock
+! !
+
+!ConstantAspectPluggableEnactInterest methodsFor: 'action'!
+
+close
+	actionBlock := nil
+!
+
+enact
+	actionBlock value
+! !
+
+!ConstantAspectPluggableEnactInterest methodsFor: 'initialization'!
+
+initialize
+	super initialize.
+    aspect := nil.
+    actionBlock := nil.
+! !
+
+!ConstantAspectPluggableEnactInterest methodsFor: 'testing'!
+
+isClosed
+	^actionBlock isNil
+! !
+
+ConstantAspectPluggableEnactInterest subclass: #InterestedInEqual
 	instanceVariableNames: ''
 	package: 'Axxord'!
 
@@ -229,7 +265,7 @@ accepts: anAspect
     ^ anAspect = aspect
 ! !
 
-AxonInterest subclass: #InterestedThruAxes
+ConstantAspectPluggableEnactInterest subclass: #InterestedThruAxes
 	instanceVariableNames: ''
 	package: 'Axxord'!
 
@@ -241,7 +277,7 @@ accepts: anAspect
 		ifFalse: [aspect = (anAspect copyFrom: 1 to: aspect size)]
 ! !
 
-AxonInterest subclass: #InterestedUpToAxes
+ConstantAspectPluggableEnactInterest subclass: #InterestedUpToAxes
 	instanceVariableNames: ''
 	package: 'Axxord'!