Browse Source

trapShow: and trapBind: merged into trap:

Herbert Vojčík 12 years ago
parent
commit
8b1f925d47
6 changed files with 135 additions and 159 deletions
  1. 6 6
      js/Trapped-Demo.deploy.js
  2. 8 8
      js/Trapped-Demo.js
  3. 45 51
      js/Trapped-Frontend.deploy.js
  4. 57 73
      js/Trapped-Frontend.js
  5. 6 6
      st/Trapped-Demo.st
  6. 13 15
      st/Trapped-Frontend.st

+ 6 - 6
js/Trapped-Demo.deploy.js

@@ -29,10 +29,10 @@ selector: "renderOn:",
 fn: function (html){
 var self=this;
 var $1,$2,$3,$4;
-smalltalk.send(smalltalk.send(html,"_h2",[]),"_trapShow_",[["title"]]);
+smalltalk.send(smalltalk.send(html,"_h2",[]),"_trap_",[["title"]]);
 smalltalk.send(smalltalk.send(html,"_div",[]),"_trap_toggle_ifNotPresent_",[["items"],(function(){
 smalltalk.send(smalltalk.send(html,"_p",[]),"_with_",[(function(){
-smalltalk.send(smalltalk.send(html,"_span",[]),"_trapShow_",[[smalltalk.symbolFor("size")]]);
+smalltalk.send(smalltalk.send(html,"_span",[]),"_trap_",[[smalltalk.symbolFor("size")]]);
 return smalltalk.send(html,"_with_",[" item(s)."]);
 })]);
 smalltalk.send(smalltalk.send(html,"_form",[]),"_with_",[(function(){
@@ -40,9 +40,9 @@ return smalltalk.send(smalltalk.send(html,"_ul",[]),"_trapIter_tag_do_",[[],smal
 smalltalk.send(smalltalk.send(html,"_root",[]),"_empty",[]);
 $1=smalltalk.send(html,"_input",[]);
 smalltalk.send($1,"_type_",["checkbox"]);
-$2=smalltalk.send($1,"_trapBind_",[[(1)]]);
+$2=smalltalk.send($1,"_trap_",[[(1)]]);
 $2;
-return smalltalk.send(smalltalk.send(html,"_span",[]),"_trapShow_",[[(2)]]);
+return smalltalk.send(smalltalk.send(html,"_span",[]),"_trap_",[[(2)]]);
 })]);
 })]);
 smalltalk.send(smalltalk.send(html,"_p",[]),"_with_",["... and again, to see the bidirectional binding:"]);
@@ -51,9 +51,9 @@ return smalltalk.send(smalltalk.send(html,"_ul",[]),"_trapIter_tag_do_",[[],smal
 smalltalk.send(smalltalk.send(html,"_root",[]),"_empty",[]);
 $3=smalltalk.send(html,"_input",[]);
 smalltalk.send($3,"_type_",["checkbox"]);
-$4=smalltalk.send($3,"_trapBind_",[[(1)]]);
+$4=smalltalk.send($3,"_trap_",[[(1)]]);
 $4;
-return smalltalk.send(smalltalk.send(html,"_span",[]),"_trapShow_",[[(2)]]);
+return smalltalk.send(smalltalk.send(html,"_span",[]),"_trap_",[[(2)]]);
 })]);
 })]);
 }),(function(){

+ 8 - 8
js/Trapped-Demo.js

@@ -35,10 +35,10 @@ category: 'rendering',
 fn: function (html){
 var self=this;
 var $1,$2,$3,$4;
-smalltalk.send(smalltalk.send(html,"_h2",[]),"_trapShow_",[["title"]]);
+smalltalk.send(smalltalk.send(html,"_h2",[]),"_trap_",[["title"]]);
 smalltalk.send(smalltalk.send(html,"_div",[]),"_trap_toggle_ifNotPresent_",[["items"],(function(){
 smalltalk.send(smalltalk.send(html,"_p",[]),"_with_",[(function(){
-smalltalk.send(smalltalk.send(html,"_span",[]),"_trapShow_",[[smalltalk.symbolFor("size")]]);
+smalltalk.send(smalltalk.send(html,"_span",[]),"_trap_",[[smalltalk.symbolFor("size")]]);
 return smalltalk.send(html,"_with_",[" item(s)."]);
 })]);
 smalltalk.send(smalltalk.send(html,"_form",[]),"_with_",[(function(){
@@ -46,9 +46,9 @@ return smalltalk.send(smalltalk.send(html,"_ul",[]),"_trapIter_tag_do_",[[],smal
 smalltalk.send(smalltalk.send(html,"_root",[]),"_empty",[]);
 $1=smalltalk.send(html,"_input",[]);
 smalltalk.send($1,"_type_",["checkbox"]);
-$2=smalltalk.send($1,"_trapBind_",[[(1)]]);
+$2=smalltalk.send($1,"_trap_",[[(1)]]);
 $2;
-return smalltalk.send(smalltalk.send(html,"_span",[]),"_trapShow_",[[(2)]]);
+return smalltalk.send(smalltalk.send(html,"_span",[]),"_trap_",[[(2)]]);
 })]);
 })]);
 smalltalk.send(smalltalk.send(html,"_p",[]),"_with_",["... and again, to see the bidirectional binding:"]);
@@ -57,9 +57,9 @@ return smalltalk.send(smalltalk.send(html,"_ul",[]),"_trapIter_tag_do_",[[],smal
 smalltalk.send(smalltalk.send(html,"_root",[]),"_empty",[]);
 $3=smalltalk.send(html,"_input",[]);
 smalltalk.send($3,"_type_",["checkbox"]);
-$4=smalltalk.send($3,"_trapBind_",[[(1)]]);
+$4=smalltalk.send($3,"_trap_",[[(1)]]);
 $4;
-return smalltalk.send(smalltalk.send(html,"_span",[]),"_trapShow_",[[(2)]]);
+return smalltalk.send(smalltalk.send(html,"_span",[]),"_trap_",[[(2)]]);
 })]);
 })]);
 }),(function(){
@@ -67,8 +67,8 @@ return smalltalk.send(html,"_with_",["Loading ..."]);
 })]);
 return self},
 args: ["html"],
-source: "renderOn: html\x0a\x09html h2 trapShow: #('title').\x0a    html div trap: #('items') toggle: [\x0a        html p with: [ html span trapShow: #(#size). html with: ' item(s).' ].\x0a\x09\x09html form with: [ html ul trapIter: #() tag: #li do: [ :each |\x0a            html root empty.\x0a            html input\x0a                type: 'checkbox';\x0a                trapBind: #(1).\x0a            html span trapShow: #(2).\x0a        ]].\x0a        html p with: '... and again, to see the bidirectional binding:'.\x0a\x09\x09html form with: [ html ul trapIter: #() tag: #li do: [ :each |\x0a            html root empty.\x0a            html input\x0a                type: 'checkbox';\x0a                trapBind: #(1).\x0a            html span trapShow: #(2).\x0a        ]].\x0a    ] ifNotPresent: [ html with: 'Loading ...' ]",
-messageSends: ["trapShow:", "h2", "trap:toggle:ifNotPresent:", "with:", "span", "p", "trapIter:tag:do:", "empty", "root", "type:", "input", "trapBind:", "ul", "form", "div"],
+source: "renderOn: html\x0a\x09html h2 trap: #('title').\x0a    html div trap: #('items') toggle: [\x0a        html p with: [ html span trap: #(#size). html with: ' item(s).' ].\x0a\x09\x09html form with: [ html ul trapIter: #() tag: #li do: [ :each |\x0a            html root empty.\x0a            html input\x0a                type: 'checkbox';\x0a                trap: #(1).\x0a            html span trap: #(2).\x0a        ]].\x0a        html p with: '... and again, to see the bidirectional binding:'.\x0a\x09\x09html form with: [ html ul trapIter: #() tag: #li do: [ :each |\x0a            html root empty.\x0a            html input\x0a                type: 'checkbox';\x0a                trap: #(1).\x0a            html span trap: #(2).\x0a        ]].\x0a    ] ifNotPresent: [ html with: 'Loading ...' ]",
+messageSends: ["trap:", "h2", "trap:toggle:ifNotPresent:", "with:", "span", "p", "trapIter:tag:do:", "empty", "root", "type:", "input", "ul", "form", "div"],
 referencedClasses: []
 }),
 smalltalk.AppView);

+ 45 - 51
js/Trapped-Frontend.deploy.js

@@ -40,8 +40,20 @@ smalltalk.method({
 selector: "showBlock",
 fn: function (){
 var self=this;
-smalltalk.send(self,"_subclassResponsibility",[]);
-return self}
+var $3,$2,$1;
+$1=(function(model){
+smalltalk.send(self["@brush"],"_empty",[]);
+if(($receiver = model) == nil || $receiver == undefined){
+$3=(function(){
+});
+} else {
+$3=model;
+};
+$2=smalltalk.send(self["@brush"],"_with_",[$3]);
+return $2;
+});
+return $1;
+}
 }),
 smalltalk.TrappedBinder);
 
@@ -125,7 +137,7 @@ smalltalk.method({
 selector: "renderOn:",
 fn: function (html){
 var self=this;
-smalltalk.send(smalltalk.send(html,"_root",[]),"_trapShow_",[[]]);
+smalltalk.send(smalltalk.send(html,"_root",[]),"_trap_",[[]]);
 return self}
 }),
 smalltalk.TrappedDumbView);
@@ -354,13 +366,28 @@ smalltalk.method({
 selector: "binder:",
 fn: function (aTagBrush){
 var self=this;
-var $2,$3,$1;
+var $1,$2,$3,$5,$4;
+var binder;
+var tag;
+tag=smalltalk.send(smalltalk.send(aTagBrush,"_element",[]),"_nodeName",[]);
+$1=smalltalk.send(tag,"__eq",["INPUT"]);
+if(smalltalk.assert($1)){
 $2=smalltalk.send((smalltalk.TrappedAttrBinder || TrappedAttrBinder),"_new",[]);
 smalltalk.send($2,"_attr_",["checked"]);
-smalltalk.send($2,"_brush_",[aTagBrush]);
 $3=smalltalk.send($2,"_yourself",[]);
-$1=$3;
-return $1;
+binder=$3;
+binder;
+};
+if(($receiver = binder) == nil || $receiver == undefined){
+binder=smalltalk.send((smalltalk.TrappedBinder || TrappedBinder),"_new",[]);
+binder;
+} else {
+binder;
+};
+smalltalk.send(binder,"_brush_",[aTagBrush]);
+$5=smalltalk.send(binder,"_yourself",[]);
+$4=$5;
+return $4;
 }
 }),
 smalltalk.Trapped);
@@ -583,6 +610,17 @@ return self}
 }),
 smalltalk.Array);
 
+smalltalk.addMethod(
+"_trap_",
+smalltalk.method({
+selector: "trap:",
+fn: function (path){
+var self=this;
+smalltalk.send(smalltalk.send(smalltalk.send((smalltalk.Trapped || Trapped),"_current",[]),"_binder_",[self]),"_installFor_",[path]);
+return self}
+}),
+smalltalk.TagBrush);
+
 smalltalk.addMethod(
 "_trap_modify_",
 smalltalk.method({
@@ -675,17 +713,6 @@ return self}
 }),
 smalltalk.TagBrush);
 
-smalltalk.addMethod(
-"_trapBind_",
-smalltalk.method({
-selector: "trapBind:",
-fn: function (path){
-var self=this;
-smalltalk.send(smalltalk.send(smalltalk.send((smalltalk.Trapped || Trapped),"_current",[]),"_binder_",[self]),"_installFor_",[path]);
-return self}
-}),
-smalltalk.TagBrush);
-
 smalltalk.addMethod(
 "_trapIter_tag_do_",
 smalltalk.method({
@@ -706,36 +733,3 @@ return self}
 }),
 smalltalk.TagBrush);
 
-smalltalk.addMethod(
-"_trapShow_",
-smalltalk.method({
-selector: "trapShow:",
-fn: function (path){
-var self=this;
-smalltalk.send(self,"_trapShow_default_",[path,(function(){
-})]);
-return self}
-}),
-smalltalk.TagBrush);
-
-smalltalk.addMethod(
-"_trapShow_default_",
-smalltalk.method({
-selector: "trapShow:default:",
-fn: function (path,anObject){
-var self=this;
-var $2,$1;
-smalltalk.send(self,"_trap_read_",[path,(function(model){
-smalltalk.send(self,"_empty",[]);
-if(($receiver = model) == nil || $receiver == undefined){
-$2=anObject;
-} else {
-$2=model;
-};
-$1=smalltalk.send(self,"_with_",[$2]);
-return $1;
-})]);
-return self}
-}),
-smalltalk.TagBrush);
-

+ 57 - 73
js/Trapped-Frontend.js

@@ -56,11 +56,23 @@ selector: "showBlock",
 category: 'action',
 fn: function (){
 var self=this;
-smalltalk.send(self,"_subclassResponsibility",[]);
-return self},
+var $3,$2,$1;
+$1=(function(model){
+smalltalk.send(self["@brush"],"_empty",[]);
+if(($receiver = model) == nil || $receiver == undefined){
+$3=(function(){
+});
+} else {
+$3=model;
+};
+$2=smalltalk.send(self["@brush"],"_with_",[$3]);
+return $2;
+});
+return $1;
+},
 args: [],
-source: "showBlock\x0a\x09self subclassResponsibility",
-messageSends: ["subclassResponsibility"],
+source: "showBlock\x0a\x09^[ :model | brush empty; with: (model ifNil: [[]]) ]",
+messageSends: ["empty", "with:", "ifNil:"],
 referencedClasses: []
 }),
 smalltalk.TrappedBinder);
@@ -168,11 +180,11 @@ selector: "renderOn:",
 category: 'rendering',
 fn: function (html){
 var self=this;
-smalltalk.send(smalltalk.send(html,"_root",[]),"_trapShow_",[[]]);
+smalltalk.send(smalltalk.send(html,"_root",[]),"_trap_",[[]]);
 return self},
 args: ["html"],
-source: "renderOn: html\x0a\x09html root trapShow: #()",
-messageSends: ["trapShow:", "root"],
+source: "renderOn: html\x0a\x09html root trap: #()",
+messageSends: ["trap:", "root"],
 referencedClasses: []
 }),
 smalltalk.TrappedDumbView);
@@ -480,18 +492,33 @@ selector: "binder:",
 category: 'binders',
 fn: function (aTagBrush){
 var self=this;
-var $2,$3,$1;
+var $1,$2,$3,$5,$4;
+var binder;
+var tag;
+tag=smalltalk.send(smalltalk.send(aTagBrush,"_element",[]),"_nodeName",[]);
+$1=smalltalk.send(tag,"__eq",["INPUT"]);
+if(smalltalk.assert($1)){
 $2=smalltalk.send((smalltalk.TrappedAttrBinder || TrappedAttrBinder),"_new",[]);
 smalltalk.send($2,"_attr_",["checked"]);
-smalltalk.send($2,"_brush_",[aTagBrush]);
 $3=smalltalk.send($2,"_yourself",[]);
-$1=$3;
-return $1;
+binder=$3;
+binder;
+};
+if(($receiver = binder) == nil || $receiver == undefined){
+binder=smalltalk.send((smalltalk.TrappedBinder || TrappedBinder),"_new",[]);
+binder;
+} else {
+binder;
+};
+smalltalk.send(binder,"_brush_",[aTagBrush]);
+$5=smalltalk.send(binder,"_yourself",[]);
+$4=$5;
+return $4;
 },
 args: ["aTagBrush"],
-source: "binder: aTagBrush\x0a    \x22Prototype; will select based on tag etc.\x22\x0a    ^TrappedAttrBinder new attr: 'checked'; brush: aTagBrush; yourself",
-messageSends: ["attr:", "new", "brush:", "yourself"],
-referencedClasses: ["TrappedAttrBinder"]
+source: "binder: aTagBrush\x0a    \x22Prototype; will select based on tag etc.\x22\x0a    | binder tag |\x0a    tag := aTagBrush element nodeName.\x0a    tag = 'INPUT' ifTrue: [\x0a    \x09binder := TrappedAttrBinder new attr: 'checked'; yourself\x0a    ].\x0a    binder ifNil: [ binder := TrappedBinder new ].\x0a    ^ binder brush: aTagBrush; yourself",
+messageSends: ["nodeName", "element", "ifTrue:", "attr:", "new", "yourself", "=", "ifNil:", "brush:"],
+referencedClasses: ["TrappedAttrBinder", "TrappedBinder"]
 }),
 smalltalk.Trapped);
 
@@ -778,6 +805,22 @@ referencedClasses: ["TrappedPathStack"]
 }),
 smalltalk.Array);
 
+smalltalk.addMethod(
+"_trap_",
+smalltalk.method({
+selector: "trap:",
+category: '*Trapped-Frontend',
+fn: function (path){
+var self=this;
+smalltalk.send(smalltalk.send(smalltalk.send((smalltalk.Trapped || Trapped),"_current",[]),"_binder_",[self]),"_installFor_",[path]);
+return self},
+args: ["path"],
+source: "trap: path\x0a\x09(Trapped current binder: self) installFor: path",
+messageSends: ["installFor:", "binder:", "current"],
+referencedClasses: ["Trapped"]
+}),
+smalltalk.TagBrush);
+
 smalltalk.addMethod(
 "_trap_modify_",
 smalltalk.method({
@@ -890,22 +933,6 @@ referencedClasses: []
 }),
 smalltalk.TagBrush);
 
-smalltalk.addMethod(
-"_trapBind_",
-smalltalk.method({
-selector: "trapBind:",
-category: '*Trapped-Frontend',
-fn: function (path){
-var self=this;
-smalltalk.send(smalltalk.send(smalltalk.send((smalltalk.Trapped || Trapped),"_current",[]),"_binder_",[self]),"_installFor_",[path]);
-return self},
-args: ["path"],
-source: "trapBind: path\x0a\x09(Trapped current binder: self) installFor: path",
-messageSends: ["installFor:", "binder:", "current"],
-referencedClasses: ["Trapped"]
-}),
-smalltalk.TagBrush);
-
 smalltalk.addMethod(
 "_trapIter_tag_do_",
 smalltalk.method({
@@ -931,46 +958,3 @@ referencedClasses: []
 }),
 smalltalk.TagBrush);
 
-smalltalk.addMethod(
-"_trapShow_",
-smalltalk.method({
-selector: "trapShow:",
-category: '*Trapped-Frontend',
-fn: function (path){
-var self=this;
-smalltalk.send(self,"_trapShow_default_",[path,(function(){
-})]);
-return self},
-args: ["path"],
-source: "trapShow: path\x0a\x09self trapShow: path default: []",
-messageSends: ["trapShow:default:"],
-referencedClasses: []
-}),
-smalltalk.TagBrush);
-
-smalltalk.addMethod(
-"_trapShow_default_",
-smalltalk.method({
-selector: "trapShow:default:",
-category: '*Trapped-Frontend',
-fn: function (path,anObject){
-var self=this;
-var $2,$1;
-smalltalk.send(self,"_trap_read_",[path,(function(model){
-smalltalk.send(self,"_empty",[]);
-if(($receiver = model) == nil || $receiver == undefined){
-$2=anObject;
-} else {
-$2=model;
-};
-$1=smalltalk.send(self,"_with_",[$2]);
-return $1;
-})]);
-return self},
-args: ["path", "anObject"],
-source: "trapShow: path default: anObject\x0a\x09self trap: path read: [ :model | self empty; with: (model ifNil: [anObject]) ]",
-messageSends: ["trap:read:", "empty", "with:", "ifNil:"],
-referencedClasses: []
-}),
-smalltalk.TagBrush);
-

+ 6 - 6
st/Trapped-Demo.st

@@ -21,23 +21,23 @@ Widget subclass: #AppView
 !AppView methodsFor: 'rendering'!
 
 renderOn: html
-	html h2 trapShow: #('title').
+	html h2 trap: #('title').
     html div trap: #('items') toggle: [
-        html p with: [ html span trapShow: #(#size). html with: ' item(s).' ].
+        html p with: [ html span trap: #(#size). html with: ' item(s).' ].
 		html form with: [ html ul trapIter: #() tag: #li do: [ :each |
             html root empty.
             html input
                 type: 'checkbox';
-                trapBind: #(1).
-            html span trapShow: #(2).
+                trap: #(1).
+            html span trap: #(2).
         ]].
         html p with: '... and again, to see the bidirectional binding:'.
 		html form with: [ html ul trapIter: #() tag: #li do: [ :each |
             html root empty.
             html input
                 type: 'checkbox';
-                trapBind: #(1).
-            html span trapShow: #(2).
+                trap: #(1).
+            html span trap: #(2).
         ]].
     ] ifNotPresent: [ html with: 'Loading ...' ]
 ! !

+ 13 - 15
st/Trapped-Frontend.st

@@ -16,7 +16,7 @@ installFor: path
 !
 
 showBlock
-	self subclassResponsibility
+	^[ :model | brush empty; with: (model ifNil: [[]]) ]
 ! !
 
 !TrappedBinder methodsFor: 'converting'!
@@ -80,7 +80,7 @@ I just read and show an actual path.!
 !TrappedDumbView methodsFor: 'rendering'!
 
 renderOn: html
-	html root trapShow: #()
+	html root trap: #()
 ! !
 
 Object subclass: #TrappedModelWrapper
@@ -242,7 +242,13 @@ start
 
 binder: aTagBrush
     "Prototype; will select based on tag etc."
-    ^TrappedAttrBinder new attr: 'checked'; brush: aTagBrush; yourself
+    | binder tag |
+    tag := aTagBrush element nodeName.
+    tag = 'INPUT' ifTrue: [
+    	binder := TrappedAttrBinder new attr: 'checked'; yourself
+    ].
+    binder ifNil: [ binder := TrappedBinder new ].
+    ^ binder brush: aTagBrush; yourself
 ! !
 
 !Trapped methodsFor: 'initialization'!
@@ -320,6 +326,10 @@ trapDescend: aBlock
 
 !TagBrush methodsFor: '*Trapped-Frontend'!
 
+trap: path
+	(Trapped current binder: self) installFor: path
+!
+
 trap: path modify: aBlock
 	path trapDescend: [ | actual model |
     	actual := Trapped path.
@@ -355,10 +365,6 @@ trap: path toggle: aBlock ifNotPresent: anotherBlock
     ]
 !
 
-trapBind: path
-	(Trapped current binder: self) installFor: path
-!
-
 trapIter: path tag: aSymbol do: aBlock
     self trap: path read: [ :model :html |
         html root empty.
@@ -366,13 +372,5 @@ trapIter: path tag: aSymbol do: aBlock
             (html perform: aSymbol) trap: {i} read: aBlock
         ]]
     ]
-!
-
-trapShow: path
-	self trapShow: path default: []
-!
-
-trapShow: path default: anObject
-	self trap: path read: [ :model | self empty; with: (model ifNil: [anObject]) ]
 ! !