Browse Source

Move responsibility near to change, via root:do:.

Herby Vojčík 4 years ago
parent
commit
89a4485655
2 changed files with 42 additions and 16 deletions
  1. 33 11
      src/Web.js
  2. 9 5
      src/Web.st

+ 33 - 11
src/Web.js

@@ -2054,6 +2054,35 @@ messageSends: []
 }),
 $globals.HTMLCanvas);
 
+$core.addMethod(
+$core.method({
+selector: "root:do:",
+protocol: "adding",
+fn: function (aTagBrush,aBlock){
+var self=this,$self=this;
+var old;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+old=$self.root;
+$self.root=aTagBrush;
+$recv(aBlock)._value_(self);
+$self.root=old;
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"root:do:",{aTagBrush:aTagBrush,aBlock:aBlock,old:old})});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["aTagBrush", "aBlock"],
+source: "root: aTagBrush do: aBlock\x0a\x09| old |\x0a\x09old := root.\x0a\x09root := aTagBrush.\x0a\x09aBlock value: self.\x0a\x09root := old",
+referencedClasses: [],
+//>>excludeEnd("ide");
+pragmas: [],
+messageSends: ["value:"]
+}),
+$globals.HTMLCanvas);
+
 $core.addMethod(
 $core.method({
 selector: "script",
@@ -2943,29 +2972,22 @@ selector: "appendBlock:",
 protocol: "adding",
 fn: function (aBlock){
 var self=this,$self=this;
-var root;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-root=$recv($self.canvas)._root();
-$recv($self.canvas)._root_(self);
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["root:"]=1;
-//>>excludeEnd("ctx");
-$recv(aBlock)._value_($self.canvas);
-$recv($self.canvas)._root_(root);
+$recv($self.canvas)._root_do_(self,aBlock);
 return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"appendBlock:",{aBlock:aBlock,root:root})});
+}, function($ctx1) {$ctx1.fill(self,"appendBlock:",{aBlock:aBlock})});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["aBlock"],
-source: "appendBlock: aBlock\x0a\x09| root |\x0a\x09root := canvas root.\x0a\x09canvas root: self.\x0a\x09aBlock value: canvas.\x0a\x09canvas root: root",
+source: "appendBlock: aBlock\x0a\x09canvas root: self do: aBlock",
 referencedClasses: [],
 //>>excludeEnd("ide");
 pragmas: [],
-messageSends: ["root", "root:", "value:"]
+messageSends: ["root:do:"]
 }),
 $globals.TagBrush);
 

+ 9 - 5
src/Web.st

@@ -43,6 +43,14 @@ entity: aString
 	self with: result
 !
 
+root: aTagBrush do: aBlock
+	| old |
+	old := root.
+	root := aTagBrush.
+	aBlock value: self.
+	root := old
+!
+
 with: anObject
 	^ self root with: anObject
 ! !
@@ -553,11 +561,7 @@ append: anObject
 !
 
 appendBlock: aBlock
-	| root |
-	root := canvas root.
-	canvas root: self.
-	aBlock value: canvas.
-	canvas root: root
+	canvas root: self do: aBlock
 !
 
 appendChild: anElement