Browse Source

Refactor Axon and SimpleAxon.

Herbert Vojčík 6 years ago
parent
commit
9fc55e9ccb
2 changed files with 110 additions and 24 deletions
  1. 80 8
      src/Axxord.js
  2. 30 16
      src/Axxord.st

+ 80 - 8
src/Axxord.js

@@ -430,10 +430,34 @@ $core.addClass("Axon", $globals.Object, ["factory"], "Axxord");
 //>>excludeStart("ide", pragmas.excludeIdeData);
 $globals.Axon.comment="I represent a pub-sub based on a key (called 'aspect').\x0aI manage aspect-block subscriptions (called 'interests') as well as run blocks of dirtied interests.\x0aThe interest objects are responsible of decision if the change of an aspect is relevant for them.\x0aInterest object must be subclasses of `AxonInterest`.\x0a\x0aMy subclasses must provide implementation for:\x0a\x0a - add:\x0a - do:\x0a - clean";
 //>>excludeEnd("ide");
+$core.addMethod(
+$core.method({
+selector: "add:",
+protocol: "primitive ops",
+fn: function (anInterest){
+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,"add:",{anInterest:anInterest},$globals.Axon)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["anInterest"],
+source: "add: anInterest\x0a\x09self subclassResponsibility",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["subclassResponsibility"]
+}),
+$globals.Axon);
+
 $core.addMethod(
 $core.method({
 selector: "addInterest:",
-protocol: "action",
+protocol: "accessing",
 fn: function (anInterest){
 var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
@@ -461,7 +485,7 @@ $globals.Axon);
 $core.addMethod(
 $core.method({
 selector: "changed:",
-protocol: "action",
+protocol: "change-update",
 fn: function (anAspect){
 var self=this,$self=this;
 var needsToRun;
@@ -502,7 +526,7 @@ $globals.Axon);
 $core.addMethod(
 $core.method({
 selector: "changedAll",
-protocol: "action",
+protocol: "change-update",
 fn: function (){
 var self=this,$self=this;
 var needsToRun;
@@ -536,10 +560,34 @@ messageSends: ["do:", "flag", "dirty:"]
 }),
 $globals.Axon);
 
+$core.addMethod(
+$core.method({
+selector: "clean",
+protocol: "primitive ops",
+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,"clean",{},$globals.Axon)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "clean\x0a\x09self subclassResponsibility",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["subclassResponsibility"]
+}),
+$globals.Axon);
+
 $core.addMethod(
 $core.method({
 selector: "dirty:",
-protocol: "action",
+protocol: "private",
 fn: function (aBoolean){
 var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
@@ -570,10 +618,34 @@ messageSends: ["ifTrue:", "fork", "run"]
 }),
 $globals.Axon);
 
+$core.addMethod(
+$core.method({
+selector: "do:",
+protocol: "primitive ops",
+fn: function (aBlock){
+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,"do:",{aBlock:aBlock},$globals.Axon)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["aBlock"],
+source: "do: aBlock\x0a\x09self subclassResponsibility",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["subclassResponsibility"]
+}),
+$globals.Axon);
+
 $core.addMethod(
 $core.method({
 selector: "run",
-protocol: "action",
+protocol: "private",
 fn: function (){
 var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
@@ -640,7 +712,7 @@ $core.addClass("SimpleAxon", $globals.Axon, ["queue"], "Axxord");
 $core.addMethod(
 $core.method({
 selector: "add:",
-protocol: "accessing",
+protocol: "primitive ops",
 fn: function (aSubscription){
 var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
@@ -664,7 +736,7 @@ $globals.SimpleAxon);
 $core.addMethod(
 $core.method({
 selector: "clean",
-protocol: "bookkeeping",
+protocol: "primitive ops",
 fn: function (){
 var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
@@ -696,7 +768,7 @@ $globals.SimpleAxon);
 $core.addMethod(
 $core.method({
 selector: "do:",
-protocol: "enumeration",
+protocol: "primitive ops",
 fn: function (aBlock){
 var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);

+ 30 - 16
src/Axxord.st

@@ -92,13 +92,15 @@ My subclasses must provide implementation for:
  - do:
  - clean!
 
-!Axon methodsFor: 'action'!
+!Axon methodsFor: 'accessing'!
 
 addInterest: anInterest
 	self
 		add: (anInterest flag; yourself);
 		dirty: true
-!
+! !
+
+!Axon methodsFor: 'change-update'!
 
 changed: anAspect
 	| needsToRun |
@@ -117,8 +119,24 @@ changedAll
 		each flag.
 		needsToRun := true ].
 	self dirty: needsToRun
+! !
+
+!Axon methodsFor: 'primitive ops'!
+
+add: anInterest
+	self subclassResponsibility
+!
+
+clean
+	self subclassResponsibility
 !
 
+do: aBlock
+	self subclassResponsibility
+! !
+
+!Axon methodsFor: 'private'!
+
 dirty: aBoolean
 	aBoolean ifTrue: [[ self run ] fork]
 !
@@ -139,31 +157,27 @@ Axon subclass: #SimpleAxon
 	instanceVariableNames: 'queue'
 	package: 'Axxord'!
 
-!SimpleAxon methodsFor: 'accessing'!
+!SimpleAxon methodsFor: 'initialization'!
 
-add: aSubscription
-	queue add: aSubscription.
+initialize
+    super initialize.
+	queue := OrderedCollection new
 ! !
 
-!SimpleAxon methodsFor: 'bookkeeping'!
+!SimpleAxon methodsFor: 'primitive ops'!
+
+add: aSubscription
+	queue add: aSubscription.
+!
 
 clean
 	queue := queue reject: [ :each | each isClosed ]
-! !
-
-!SimpleAxon methodsFor: 'enumeration'!
+!
 
 do: aBlock
 	queue do: aBlock
 ! !
 
-!SimpleAxon methodsFor: 'initialization'!
-
-initialize
-    super initialize.
-	queue := OrderedCollection new
-! !
-
 Object subclass: #AxonInterest
 	instanceVariableNames: 'flagged'
 	package: 'Axxord'!