Browse Source

trapShow:, trap:read:, faked async filling

Herbert Vojčík 12 years ago
parent
commit
1fb0d33a89
7 changed files with 174 additions and 53 deletions
  1. 1 2
      demo.html
  2. 25 2
      js/Trapped-Demo.deploy.js
  3. 35 2
      js/Trapped-Demo.js
  4. 36 14
      js/Trapped-Frontend.deploy.js
  5. 47 20
      js/Trapped-Frontend.js
  6. 15 2
      st/Trapped-Demo.st
  7. 15 11
      st/Trapped-Frontend.st

+ 1 - 2
demo.html

@@ -1,6 +1,6 @@
 <html>
 <head>
-    <title data-trap="NameView:Name">[placeholder:Name]</title>
+    <title data-trap="NameView:Name"></title>
     <script src="/vendor/amber/js/amber.js"></script>
 </head>
 <body>
@@ -19,7 +19,6 @@
     });
 </script>
 <div data-trap="AppView:App">
-    [placeholder:App]
 </div>
 </body>
 </html>

+ 25 - 2
js/Trapped-Demo.deploy.js

@@ -2,12 +2,35 @@ smalltalk.addPackage('Trapped-Demo', {});
 smalltalk.addClass('App', smalltalk.TrappedFly, [], 'Trapped-Demo');
 
 
-smalltalk.addClass('AppView', smalltalk.TrappedView, [], 'Trapped-Demo');
+smalltalk.addClass('AppView', smalltalk.Widget, [], 'Trapped-Demo');
+smalltalk.addMethod(
+"_renderOn_",
+smalltalk.method({
+selector: "renderOn:",
+fn: function (html){
+var self=this;
+smalltalk.send(html,"_h2_",["To-Do List"]);
+smalltalk.send(smalltalk.send(html,"_p",[]),"_trapShow_",[["items"]]);
+return self}
+}),
+smalltalk.AppView);
+
 
 
 smalltalk.addClass('Name', smalltalk.TrappedFly, [], 'Trapped-Demo');
 
 
-smalltalk.addClass('NameView', smalltalk.TrappedView, [], 'Trapped-Demo');
+smalltalk.addClass('NameView', smalltalk.Widget, [], 'Trapped-Demo');
+smalltalk.addMethod(
+"_renderOn_",
+smalltalk.method({
+selector: "renderOn:",
+fn: function (html){
+var self=this;
+smalltalk.send(smalltalk.send(html,"_root",[]),"_trapShow_",[[]]);
+return self}
+}),
+smalltalk.NameView);
+
 
 

+ 35 - 2
js/Trapped-Demo.js

@@ -2,12 +2,45 @@ smalltalk.addPackage('Trapped-Demo', {});
 smalltalk.addClass('App', smalltalk.TrappedFly, [], 'Trapped-Demo');
 
 
-smalltalk.addClass('AppView', smalltalk.TrappedView, [], 'Trapped-Demo');
+smalltalk.addClass('AppView', smalltalk.Widget, [], 'Trapped-Demo');
+smalltalk.addMethod(
+"_renderOn_",
+smalltalk.method({
+selector: "renderOn:",
+category: 'rendering',
+fn: function (html){
+var self=this;
+smalltalk.send(html,"_h2_",["To-Do List"]);
+smalltalk.send(smalltalk.send(html,"_p",[]),"_trapShow_",[["items"]]);
+return self},
+args: ["html"],
+source: "renderOn: html\x0a\x09html h2: 'To-Do List'.\x0a\x09html p trapShow: #('items')",
+messageSends: ["h2:", "trapShow:", "p"],
+referencedClasses: []
+}),
+smalltalk.AppView);
+
 
 
 smalltalk.addClass('Name', smalltalk.TrappedFly, [], 'Trapped-Demo');
 
 
-smalltalk.addClass('NameView', smalltalk.TrappedView, [], 'Trapped-Demo');
+smalltalk.addClass('NameView', smalltalk.Widget, [], 'Trapped-Demo');
+smalltalk.addMethod(
+"_renderOn_",
+smalltalk.method({
+selector: "renderOn:",
+category: 'rendering',
+fn: function (html){
+var self=this;
+smalltalk.send(smalltalk.send(html,"_root",[]),"_trapShow_",[[]]);
+return self},
+args: ["html"],
+source: "renderOn: html\x0a\x09html root trapShow: #()",
+messageSends: ["trapShow:", "root"],
+referencedClasses: []
+}),
+smalltalk.NameView);
+
 
 

+ 36 - 14
js/Trapped-Frontend.deploy.js

@@ -220,20 +220,16 @@ smalltalk.TrappedPathStack);
 
 
 
-smalltalk.addClass('TrappedView', smalltalk.Widget, [], 'Trapped-Frontend');
 smalltalk.addMethod(
-"_renderOn_",
+"_trapDescend_",
 smalltalk.method({
-selector: "renderOn:",
-fn: function (html){
+selector: "trapDescend:",
+fn: function (aBlock){
 var self=this;
-smalltalk.send(smalltalk.send(html,"_root",[]),"_empty",[]);
-smalltalk.send(html,"_with_",[smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(self,"_class",[]),"_name",[]),"__comma",[": "]),"__comma",[smalltalk.send((smalltalk.Trapped || Trapped),"_path",[])])]);
+smalltalk.send(smalltalk.send((smalltalk.TrappedPathStack || TrappedPathStack),"_current",[]),"_with_do_",[self,aBlock]);
 return self}
 }),
-smalltalk.TrappedView);
-
-
+smalltalk.Array);
 
 smalltalk.addMethod(
 "_trapDescend_",
@@ -247,13 +243,39 @@ return self}
 smalltalk.Array);
 
 smalltalk.addMethod(
-"_trapDescend_",
+"_trap_read_",
 smalltalk.method({
-selector: "trapDescend:",
-fn: function (aBlock){
+selector: "trap:read:",
+fn: function (path,aBlock){
 var self=this;
-smalltalk.send(smalltalk.send((smalltalk.TrappedPathStack || TrappedPathStack),"_current",[]),"_with_do_",[self,aBlock]);
+smalltalk.send(path,"_trapDescend_",[(function(){
+var actual;
+var model;
+actual=smalltalk.send((smalltalk.Trapped || Trapped),"_path",[]);
+actual;
+model=smalltalk.send(smalltalk.send("<< ","__comma",[actual]),"__comma",[" >>"]);
+model;
+return smalltalk.send((function(){
+return smalltalk.send(aBlock,"_value_value_",[self,model]);
+}),"_fork",[]);
+})]);
 return self}
 }),
-smalltalk.Array);
+smalltalk.TagBrush);
+
+smalltalk.addMethod(
+"_trapShow_",
+smalltalk.method({
+selector: "trapShow:",
+fn: function (path){
+var self=this;
+var $1;
+smalltalk.send(self,"_trap_read_",[path,(function(brush,model){
+smalltalk.send(brush,"_empty",[]);
+$1=smalltalk.send(brush,"_with_",[model]);
+return $1;
+})]);
+return self}
+}),
+smalltalk.TagBrush);
 

+ 47 - 20
js/Trapped-Frontend.js

@@ -295,26 +295,6 @@ smalltalk.TrappedPathStack);
 
 
 
-smalltalk.addClass('TrappedView', smalltalk.Widget, [], 'Trapped-Frontend');
-smalltalk.addMethod(
-"_renderOn_",
-smalltalk.method({
-selector: "renderOn:",
-category: 'rendering',
-fn: function (html){
-var self=this;
-smalltalk.send(smalltalk.send(html,"_root",[]),"_empty",[]);
-smalltalk.send(html,"_with_",[smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(self,"_class",[]),"_name",[]),"__comma",[": "]),"__comma",[smalltalk.send((smalltalk.Trapped || Trapped),"_path",[])])]);
-return self},
-args: ["html"],
-source: "renderOn: html\x0a\x09html root empty.\x0a\x09html with: self class name, ': ', Trapped path",
-messageSends: ["empty", "root", "with:", ",", "path", "name", "class"],
-referencedClasses: ["Trapped"]
-}),
-smalltalk.TrappedView);
-
-
-
 smalltalk.addMethod(
 "_trapDescend_",
 smalltalk.method({
@@ -347,3 +327,50 @@ referencedClasses: ["TrappedPathStack"]
 }),
 smalltalk.Array);
 
+smalltalk.addMethod(
+"_trap_read_",
+smalltalk.method({
+selector: "trap:read:",
+category: '*Trapped-Frontend',
+fn: function (path,aBlock){
+var self=this;
+smalltalk.send(path,"_trapDescend_",[(function(){
+var actual;
+var model;
+actual=smalltalk.send((smalltalk.Trapped || Trapped),"_path",[]);
+actual;
+model=smalltalk.send(smalltalk.send("<< ","__comma",[actual]),"__comma",[" >>"]);
+model;
+return smalltalk.send((function(){
+return smalltalk.send(aBlock,"_value_value_",[self,model]);
+}),"_fork",[]);
+})]);
+return self},
+args: ["path", "aBlock"],
+source: "trap: path read: aBlock\x0a\x09path trapDescend: [ | actual model |\x0a    \x09actual := Trapped path.\x0a        model := '<< ', actual, ' >>'.\x0a       \x09\x22TODO register for later\x22\x0a        [aBlock value: self value: model] fork\x0a    ]",
+messageSends: ["trapDescend:", "path", ",", "fork", "value:value:"],
+referencedClasses: ["Trapped"]
+}),
+smalltalk.TagBrush);
+
+smalltalk.addMethod(
+"_trapShow_",
+smalltalk.method({
+selector: "trapShow:",
+category: '*Trapped-Frontend',
+fn: function (path){
+var self=this;
+var $1;
+smalltalk.send(self,"_trap_read_",[path,(function(brush,model){
+smalltalk.send(brush,"_empty",[]);
+$1=smalltalk.send(brush,"_with_",[model]);
+return $1;
+})]);
+return self},
+args: ["path"],
+source: "trapShow: path\x0a\x09self trap: path read: [ :brush :model | brush empty; with: model ]",
+messageSends: ["trap:read:", "empty", "with:"],
+referencedClasses: []
+}),
+smalltalk.TagBrush);
+

+ 15 - 2
st/Trapped-Demo.st

@@ -3,15 +3,28 @@ TrappedFly subclass: #App
 	instanceVariableNames: ''
 	package: 'Trapped-Demo'!
 
-TrappedView subclass: #AppView
+Widget subclass: #AppView
 	instanceVariableNames: ''
 	package: 'Trapped-Demo'!
 
+!AppView methodsFor: 'rendering'!
+
+renderOn: html
+	html h2: 'To-Do List'.
+	html p trapShow: #('items')
+! !
+
 TrappedFly subclass: #Name
 	instanceVariableNames: ''
 	package: 'Trapped-Demo'!
 
-TrappedView subclass: #NameView
+Widget subclass: #NameView
 	instanceVariableNames: ''
 	package: 'Trapped-Demo'!
 
+!NameView methodsFor: 'rendering'!
+
+renderOn: html
+	html root trapShow: #()
+! !
+

+ 15 - 11
st/Trapped-Frontend.st

@@ -113,17 +113,6 @@ initialize
 	elements := #().
 ! !
 
-Widget subclass: #TrappedView
-	instanceVariableNames: ''
-	package: 'Trapped-Frontend'!
-
-!TrappedView methodsFor: 'rendering'!
-
-renderOn: html
-	html root empty.
-	html with: self class name, ': ', Trapped path
-! !
-
 !Array methodsFor: '*Trapped-Frontend'!
 
 trapDescend: aBlock
@@ -136,3 +125,18 @@ trapDescend: aBlock
 	TrappedPathStack current with: self do: aBlock
 ! !
 
+!TagBrush methodsFor: '*Trapped-Frontend'!
+
+trap: path read: aBlock
+	path trapDescend: [ | actual model |
+    	actual := Trapped path.
+        model := '<< ', actual, ' >>'.
+       	"TODO register for later"
+        [aBlock value: self value: model] fork
+    ]
+!
+
+trapShow: path
+	self trap: path read: [ :brush :model | brush empty; with: model ]
+! !
+