Browse Source

Lazy accessor #root.

Herby Vojčík 4 years ago
parent
commit
d77bbe1940
2 changed files with 17 additions and 50 deletions
  1. 16 44
      src/Web.js
  2. 1 6
      src/Web.st

+ 16 - 44
src/Web.js

@@ -1374,46 +1374,6 @@ messageSends: ["src:", "img"]
 }),
 $globals.HTMLCanvas);
 
-$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");
-var $1,$receiver;
-(
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.supercall = true,
-//>>excludeEnd("ctx");
-($globals.HTMLCanvas.superclass||$boot.nilAsClass).fn.prototype._initialize.apply($self, []));
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.supercall = false;
-//>>excludeEnd("ctx");;
-$1=$self.root;
-if(($receiver = $1) == null || $receiver.a$nil){
-$self.root=$recv($globals.TagBrush)._fromString_canvas_("div",self);
-$self.root;
-} else {
-$1;
-}
-return self;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"initialize",{})});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: [],
-source: "initialize\x0a\x09super initialize.\x0a\x09root ifNil: [ root := TagBrush fromString: 'div' canvas: self ]",
-referencedClasses: ["TagBrush"],
-//>>excludeEnd("ide");
-pragmas: [],
-messageSends: ["initialize", "ifNil:", "fromString:canvas:"]
-}),
-$globals.HTMLCanvas);
-
 $core.addMethod(
 $core.method({
 selector: "initializeFromJQuery:",
@@ -2021,16 +1981,28 @@ selector: "root",
 protocol: "accessing",
 fn: function (){
 var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $1,$receiver;
+$1=$self.root;
+if(($receiver = $1) == null || $receiver.a$nil){
+$self.root=$recv($globals.TagBrush)._fromString_canvas_("div",self);
 return $self.root;
-
+} else {
+return $1;
+}
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"root",{})});
+//>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "root\x0a\x09^ root",
-referencedClasses: [],
+source: "root\x0a\x09^ root ifNil: [ root := TagBrush fromString: 'div' canvas: self ]",
+referencedClasses: ["TagBrush"],
 //>>excludeEnd("ide");
 pragmas: [],
-messageSends: []
+messageSends: ["ifNil:", "fromString:canvas:"]
 }),
 $globals.HTMLCanvas);
 

+ 1 - 6
src/Web.st

@@ -23,7 +23,7 @@ The `#with:` method is used to compose HTML, nesting tags. `#with:` can take a `
 !HTMLCanvas methodsFor: 'accessing'!
 
 root
-	^ root
+	^ root ifNil: [ root := TagBrush fromString: 'div' canvas: self ]
 !
 
 root: aTagBrush
@@ -58,11 +58,6 @@ with: anObject
 
 !HTMLCanvas methodsFor: 'initialization'!
 
-initialize
-	super initialize.
-	root ifNil: [ root := TagBrush fromString: 'div' canvas: self ]
-!
-
 initializeFromJQuery: aJQuery
 	root := TagBrush fromJQuery: aJQuery canvas: self
 ! !