Browse Source

PluggableInterest, related simplifications.

Herbert Vojčík 7 years ago
parent
commit
84be616bc5
2 changed files with 188 additions and 193 deletions
  1. 154 148
      src/Axxord.js
  2. 34 45
      src/Axxord.st

+ 154 - 148
src/Axxord.js

@@ -9,6 +9,111 @@ $core.packages["Axxord"].transport = {"type":"amd","amdNamespace":"axxord"};
 
 $core.addClass("Axes", $globals.Object, [], "Axxord");
 
+$core.addMethod(
+$core.method({
+selector: "newInterestThru:doing:",
+protocol: "factory",
+fn: function (anAspect,aBlock){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $2,$3,$1,$5,$4;
+return $recv($recv($globals.PluggableInterest)._new())._accept_enact_((function(aspect){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+$2=$recv(aspect)._size();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx2.sendIdx["size"]=1;
+//>>excludeEnd("ctx");
+$3=$recv(anAspect)._size();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx2.sendIdx["size"]=2;
+//>>excludeEnd("ctx");
+$1=$recv($2).__lt_eq($3);
+if($core.assert($1)){
+$5=$recv(aspect)._size();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx2.sendIdx["size"]=3;
+//>>excludeEnd("ctx");
+$4=$recv(anAspect)._copyFrom_to_((1),$5);
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx2.sendIdx["copyFrom:to:"]=1;
+//>>excludeEnd("ctx");
+return $recv(aspect).__eq($4);
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx2.sendIdx["="]=1;
+//>>excludeEnd("ctx");
+} else {
+return $recv(anAspect).__eq($recv(aspect)._copyFrom_to_((1),$recv(anAspect)._size()));
+}
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({aspect:aspect},$ctx1,1)});
+//>>excludeEnd("ctx");
+}),aBlock);
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"newInterestThru:doing:",{anAspect:anAspect,aBlock:aBlock},$globals.Axes.a$cls)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["anAspect", "aBlock"],
+source: "newInterestThru: anAspect doing: aBlock\x0a\x09^ PluggableInterest new\x0a\x09\x09accept: [ :aspect | aspect size <= anAspect size\x0a\x09\x09\x09ifTrue: [ aspect = (anAspect copyFrom: 1 to: aspect size) ]\x0a\x09\x09\x09ifFalse: [ anAspect = (aspect copyFrom: 1 to: anAspect size) ] ]\x0a\x09\x09enact: aBlock",
+referencedClasses: ["PluggableInterest"],
+//>>excludeEnd("ide");
+messageSends: ["accept:enact:", "new", "ifTrue:ifFalse:", "<=", "size", "=", "copyFrom:to:"]
+}),
+$globals.Axes.a$cls);
+
+$core.addMethod(
+$core.method({
+selector: "newInterestUpTo:doing:",
+protocol: "factory",
+fn: function (anAspect,aBlock){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $2,$3,$1;
+return $recv($recv($globals.PluggableInterest)._new())._accept_enact_((function(changedAspect){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+$2=$recv(changedAspect)._size();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx2.sendIdx["size"]=1;
+//>>excludeEnd("ctx");
+$3=$recv(anAspect)._size();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx2.sendIdx["size"]=2;
+//>>excludeEnd("ctx");
+$1=$recv($2).__lt_eq($3);
+return $recv($1)._and_((function(){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx3) {
+//>>excludeEnd("ctx");
+return $recv(changedAspect).__eq($recv(anAspect)._copyFrom_to_((1),$recv(changedAspect)._size()));
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)});
+//>>excludeEnd("ctx");
+}));
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({changedAspect:changedAspect},$ctx1,1)});
+//>>excludeEnd("ctx");
+}),aBlock);
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"newInterestUpTo:doing:",{anAspect:anAspect,aBlock:aBlock},$globals.Axes.a$cls)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["anAspect", "aBlock"],
+source: "newInterestUpTo: anAspect doing: aBlock\x0a\x09^ PluggableInterest new\x0a\x09\x09accept: [ :changedAspect | changedAspect size <= anAspect size and:\x0a\x09\x09\x09[changedAspect = (anAspect copyFrom: 1 to: changedAspect size)] ]\x0a\x09\x09enact: aBlock",
+referencedClasses: ["PluggableInterest"],
+//>>excludeEnd("ide");
+messageSends: ["accept:enact:", "new", "and:", "<=", "size", "=", "copyFrom:to:"]
+}),
+$globals.Axes.a$cls);
+
 $core.addMethod(
 $core.method({
 selector: "parse:",
@@ -880,26 +985,49 @@ $globals.AxonInterest);
 
 
 
-$core.addClass("ConstantAspectPluggableEnactInterest", $globals.AxonInterest, ["aspect", "actionBlock"], "Axxord");
+$core.addClass("PluggableInterest", $globals.AxonInterest, ["acceptBlock", "enactBlock"], "Axxord");
 $core.addMethod(
 $core.method({
-selector: "aspect:block:",
+selector: "accept:enact:",
 protocol: "accessing",
-fn: function (anAspect,aBlock){
+fn: function (aBlock,anotherBlock){
 var self=this,$self=this;
-$self["@aspect"]=anAspect;
-$self["@actionBlock"]=aBlock;
+$self["@acceptBlock"]=aBlock;
+$self["@enactBlock"]=anotherBlock;
 return self;
 
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
-args: ["anAspect", "aBlock"],
-source: "aspect: anAspect block: aBlock\x0a\x09aspect := anAspect.\x0a    actionBlock := aBlock",
+args: ["aBlock", "anotherBlock"],
+source: "accept: aBlock enact: anotherBlock\x0a\x09acceptBlock := aBlock.\x0a    enactBlock := anotherBlock",
 referencedClasses: [],
 //>>excludeEnd("ide");
 messageSends: []
 }),
-$globals.ConstantAspectPluggableEnactInterest);
+$globals.PluggableInterest);
+
+$core.addMethod(
+$core.method({
+selector: "accepts:",
+protocol: "testing",
+fn: function (anAspect){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return $recv($self["@acceptBlock"])._value_(anAspect);
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"accepts:",{anAspect:anAspect},$globals.PluggableInterest)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["anAspect"],
+source: "accepts: anAspect\x0a    ^ acceptBlock value: anAspect",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["value:"]
+}),
+$globals.PluggableInterest);
 
 $core.addMethod(
 $core.method({
@@ -907,18 +1035,19 @@ selector: "close",
 protocol: "action",
 fn: function (){
 var self=this,$self=this;
-$self["@actionBlock"]=nil;
+$self["@acceptBlock"]=nil;
+$self["@enactBlock"]=nil;
 return self;
 
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "close\x0a\x09actionBlock := nil",
+source: "close\x0a\x09acceptBlock := nil.\x0a\x09enactBlock := nil",
 referencedClasses: [],
 //>>excludeEnd("ide");
 messageSends: []
 }),
-$globals.ConstantAspectPluggableEnactInterest);
+$globals.PluggableInterest);
 
 $core.addMethod(
 $core.method({
@@ -929,20 +1058,20 @@ var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-$recv($self["@actionBlock"])._value();
+$recv($self["@enactBlock"])._value();
 return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"enact",{},$globals.ConstantAspectPluggableEnactInterest)});
+}, function($ctx1) {$ctx1.fill(self,"enact",{},$globals.PluggableInterest)});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "enact\x0a\x09actionBlock value",
+source: "enact\x0a\x09enactBlock value",
 referencedClasses: [],
 //>>excludeEnd("ide");
 messageSends: ["value"]
 }),
-$globals.ConstantAspectPluggableEnactInterest);
+$globals.PluggableInterest);
 
 $core.addMethod(
 $core.method({
@@ -957,25 +1086,24 @@ return $core.withContext(function($ctx1) {
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.supercall = true,
 //>>excludeEnd("ctx");
-($globals.ConstantAspectPluggableEnactInterest.superclass||$boot.nilAsClass).fn.prototype._initialize.apply($self, []));
+($globals.PluggableInterest.superclass||$boot.nilAsClass).fn.prototype._initialize.apply($self, []));
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.supercall = false;
 //>>excludeEnd("ctx");;
-$self["@aspect"]=nil;
-$self["@actionBlock"]=nil;
+$self._close();
 return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.ConstantAspectPluggableEnactInterest)});
+}, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.PluggableInterest)});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "initialize\x0a\x09super initialize.\x0a    aspect := nil.\x0a    actionBlock := nil.",
+source: "initialize\x0a\x09super initialize.\x0a    self close",
 referencedClasses: [],
 //>>excludeEnd("ide");
-messageSends: ["initialize"]
+messageSends: ["initialize", "close"]
 }),
-$globals.ConstantAspectPluggableEnactInterest);
+$globals.PluggableInterest);
 
 $core.addMethod(
 $core.method({
@@ -986,141 +1114,19 @@ var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-return $recv($self["@actionBlock"])._isNil();
+return $recv($self["@acceptBlock"])._isNil();
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"isClosed",{},$globals.ConstantAspectPluggableEnactInterest)});
+}, function($ctx1) {$ctx1.fill(self,"isClosed",{},$globals.PluggableInterest)});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "isClosed\x0a\x09^actionBlock isNil",
+source: "isClosed\x0a\x09^ acceptBlock isNil",
 referencedClasses: [],
 //>>excludeEnd("ide");
 messageSends: ["isNil"]
 }),
-$globals.ConstantAspectPluggableEnactInterest);
-
-
-
-$core.addClass("InterestedInEqual", $globals.ConstantAspectPluggableEnactInterest, [], "Axxord");
-$core.addMethod(
-$core.method({
-selector: "accepts:",
-protocol: "testing",
-fn: function (anAspect){
-var self=this,$self=this;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-return $recv(anAspect).__eq($self["@aspect"]);
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"accepts:",{anAspect:anAspect},$globals.InterestedInEqual)});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: ["anAspect"],
-source: "accepts: anAspect\x0a    ^ anAspect = aspect",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: ["="]
-}),
-$globals.InterestedInEqual);
-
-
-
-$core.addClass("InterestedThruAxes", $globals.ConstantAspectPluggableEnactInterest, [], "Axxord");
-$core.addMethod(
-$core.method({
-selector: "accepts:",
-protocol: "testing",
-fn: function (anAspect){
-var self=this,$self=this;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-var $2,$3,$1,$5,$6,$4;
-$2=$recv(anAspect)._size();
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["size"]=1;
-//>>excludeEnd("ctx");
-$3=$recv($self["@aspect"])._size();
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["size"]=2;
-//>>excludeEnd("ctx");
-$1=$recv($2).__lt_eq($3);
-if($core.assert($1)){
-$5=$self["@aspect"];
-$6=$recv(anAspect)._size();
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["size"]=3;
-//>>excludeEnd("ctx");
-$4=$recv($5)._copyFrom_to_((1),$6);
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["copyFrom:to:"]=1;
-//>>excludeEnd("ctx");
-return $recv(anAspect).__eq($4);
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["="]=1;
-//>>excludeEnd("ctx");
-} else {
-return $recv($self["@aspect"]).__eq($recv(anAspect)._copyFrom_to_((1),$recv($self["@aspect"])._size()));
-}
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"accepts:",{anAspect:anAspect},$globals.InterestedThruAxes)});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: ["anAspect"],
-source: "accepts: anAspect\x0a    ^anAspect size <= aspect size\x0a\x09\x09ifTrue: [anAspect = (aspect copyFrom: 1 to: anAspect size)]\x0a\x09\x09ifFalse: [aspect = (anAspect copyFrom: 1 to: aspect size)]",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: ["ifTrue:ifFalse:", "<=", "size", "=", "copyFrom:to:"]
-}),
-$globals.InterestedThruAxes);
-
-
-
-$core.addClass("InterestedUpToAxes", $globals.ConstantAspectPluggableEnactInterest, [], "Axxord");
-$core.addMethod(
-$core.method({
-selector: "accepts:",
-protocol: "testing",
-fn: function (anAspect){
-var self=this,$self=this;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-var $2,$3,$1;
-$2=$recv(anAspect)._size();
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["size"]=1;
-//>>excludeEnd("ctx");
-$3=$recv($self["@aspect"])._size();
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["size"]=2;
-//>>excludeEnd("ctx");
-$1=$recv($2).__lt_eq($3);
-return $recv($1)._and_((function(){
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx2) {
-//>>excludeEnd("ctx");
-return $recv(anAspect).__eq($recv($self["@aspect"])._copyFrom_to_((1),$recv(anAspect)._size()));
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
-//>>excludeEnd("ctx");
-}));
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"accepts:",{anAspect:anAspect},$globals.InterestedUpToAxes)});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: ["anAspect"],
-source: "accepts: anAspect\x0a    ^anAspect size <= aspect size and: [anAspect = (aspect copyFrom: 1 to: anAspect size)]",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: ["and:", "<=", "size", "=", "copyFrom:to:"]
-}),
-$globals.InterestedUpToAxes);
+$globals.PluggableInterest);
 
 
 

+ 34 - 45
src/Axxord.st

@@ -3,6 +3,23 @@ Object subclass: #Axes
 	instanceVariableNames: ''
 	package: 'Axxord'!
 
+!Axes class methodsFor: 'factory'!
+
+newInterestThru: anAspect doing: aBlock
+	^ PluggableInterest new
+		accept: [ :aspect | aspect size <= anAspect size
+			ifTrue: [ aspect = (anAspect copyFrom: 1 to: aspect size) ]
+			ifFalse: [ anAspect = (aspect copyFrom: 1 to: anAspect size) ] ]
+		enact: aBlock
+!
+
+newInterestUpTo: anAspect doing: aBlock
+	^ PluggableInterest new
+		accept: [ :changedAspect | changedAspect size <= anAspect size and:
+			[changedAspect = (anAspect copyFrom: 1 to: changedAspect size)] ]
+		enact: aBlock
+! !
+
 !Axes class methodsFor: 'parsing'!
 
 parse: message
@@ -200,71 +217,43 @@ isFlagged
 	^flagged
 ! !
 
-AxonInterest subclass: #ConstantAspectPluggableEnactInterest
-	instanceVariableNames: 'aspect actionBlock'
+AxonInterest subclass: #PluggableInterest
+	instanceVariableNames: 'acceptBlock enactBlock'
 	package: 'Axxord'!
 
-!ConstantAspectPluggableEnactInterest methodsFor: 'accessing'!
+!PluggableInterest methodsFor: 'accessing'!
 
-aspect: anAspect block: aBlock
-	aspect := anAspect.
-    actionBlock := aBlock
+accept: aBlock enact: anotherBlock
+	acceptBlock := aBlock.
+    enactBlock := anotherBlock
 ! !
 
-!ConstantAspectPluggableEnactInterest methodsFor: 'action'!
+!PluggableInterest methodsFor: 'action'!
 
 close
-	actionBlock := nil
+	acceptBlock := nil.
+	enactBlock := nil
 !
 
 enact
-	actionBlock value
+	enactBlock value
 ! !
 
-!ConstantAspectPluggableEnactInterest methodsFor: 'initialization'!
+!PluggableInterest methodsFor: 'initialization'!
 
 initialize
 	super initialize.
-    aspect := nil.
-    actionBlock := nil.
-! !
-
-!ConstantAspectPluggableEnactInterest methodsFor: 'testing'!
-
-isClosed
-	^actionBlock isNil
-! !
-
-ConstantAspectPluggableEnactInterest subclass: #InterestedInEqual
-	instanceVariableNames: ''
-	package: 'Axxord'!
-
-!InterestedInEqual methodsFor: 'testing'!
-
-accepts: anAspect
-    ^ anAspect = aspect
+    self close
 ! !
 
-ConstantAspectPluggableEnactInterest subclass: #InterestedThruAxes
-	instanceVariableNames: ''
-	package: 'Axxord'!
-
-!InterestedThruAxes methodsFor: 'testing'!
+!PluggableInterest methodsFor: 'testing'!
 
 accepts: anAspect
-    ^anAspect size <= aspect size
-		ifTrue: [anAspect = (aspect copyFrom: 1 to: anAspect size)]
-		ifFalse: [aspect = (anAspect copyFrom: 1 to: aspect size)]
-! !
-
-ConstantAspectPluggableEnactInterest subclass: #InterestedUpToAxes
-	instanceVariableNames: ''
-	package: 'Axxord'!
-
-!InterestedUpToAxes methodsFor: 'testing'!
+    ^ acceptBlock value: anAspect
+!
 
-accepts: anAspect
-    ^anAspect size <= aspect size and: [anAspect = (aspect copyFrom: 1 to: anAspect size)]
+isClosed
+	^ acceptBlock isNil
 ! !
 
 Error subclass: #AxonOff