Browse Source

guard:trap:contents: -> trapGuard:contents:

Since only contents is changed, and only once,
there is not point for the former trap: part.
Herbert Vojčík 11 years ago
parent
commit
527242d49a
4 changed files with 63 additions and 63 deletions
  1. 5 5
      lib/js/Trapped-Demo.js
  2. 43 43
      lib/js/Trapped-Frontend.js
  3. 2 2
      lib/st/Trapped-Demo.st
  4. 13 13
      lib/st/Trapped-Frontend.st

+ 5 - 5
lib/js/Trapped-Demo.js

@@ -245,7 +245,7 @@ var $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$12,$13,$14,$15,$11;
 return smalltalk.withContext(function($ctx2) {
 _st(_st(html)._h2())._trap_([["title"]]);
 $ctx2.sendIdx["trap:"]=1;
-_st(_st(html)._div())._guard_trap_contents_([["todos"], ["notNil"]],[],(function(){
+_st(_st(html)._div())._trapGuard_contents_([["todos"], ["notNil"]],(function(){
 return smalltalk.withContext(function($ctx3) {
 $1=_st(html)._span();
 $ctx3.sendIdx["span"]=1;
@@ -328,13 +328,13 @@ return $15;
 }, function($ctx4) {$ctx4.fillBlock({},$ctx3,10)})}));
 return $11;
 }, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)})}));
-$ctx2.sendIdx["guard:trap:contents:"]=1;
-return _st(_st(html)._p())._guard_trap_contents_([["todos"], ["isNil"]],[],"Loading ...");
+$ctx2.sendIdx["trapGuard:contents:"]=1;
+return _st(_st(html)._p())._trapGuard_contents_([["todos"], ["isNil"]],"Loading ...");
 }, function($ctx2) {$ctx2.fillBlock({snap:snap},$ctx1,1)})}));
 return self}, function($ctx1) {$ctx1.fill(self,"renderOn:",{html:html},smalltalk.AppView)})},
 args: ["html"],
-source: "renderOn: html\x0a    #() trapDescend: [ :snap |\x0a\x09html h2 trap: #((title)).\x0a    html div guard: #((todos) (notNil)) trap: #() contents: [\x0a        html span trap:#((remaining)).\x0a        html with: ' of '.\x0a        html span trap: #((todos) (size)).\x0a        html with: ' remaining [ '.\x0a        html a href:''; onClick: [\x0a            snap modify: [ :model | model archive ].\x0a            false\x0a        ]; with: 'archive'.\x0a        html with: ' ]'.\x0a        html ul with: [ html trapIter: #((todos)) tag: #li do: [ :each |\x0a            html root empty.\x0a            html input type: 'checkbox'; trap: #('done').\x0a            html span trap: #('done') read: [ :model | html root class: 'done-', model ]; trap: #('text').\x0a        ]].\x0a        html form onSubmit: [\x0a            snap modify: [ :model | model addTodo ].\x0a            false\x0a        ]; with: [\x0a            html input type: 'text'; trap: #((todoText)); at: 'size' put: 30; placeholder: 'add new todo here'.\x0a            html input class: 'btn-primary'; type: 'submit'; value: 'add'.\x0a        ].\x0a    ].\x0a\x09html p guard: #((todos) (isNil)) trap: #() contents: 'Loading ...'.\x0a\x09]",
-messageSends: ["trapDescend:", "trap:", "h2", "guard:trap:contents:", "div", "span", "with:", "href:", "a", "onClick:", "modify:", "archive", "ul", "trapIter:tag:do:", "empty", "root", "type:", "input", "trap:read:", "class:", ",", "onSubmit:", "form", "addTodo", "at:put:", "placeholder:", "value:", "p"],
+source: "renderOn: html\x0a    #() trapDescend: [ :snap |\x0a\x09html h2 trap: #((title)).\x0a    html div trapGuard: #((todos) (notNil)) contents: [\x0a        html span trap:#((remaining)).\x0a        html with: ' of '.\x0a        html span trap: #((todos) (size)).\x0a        html with: ' remaining [ '.\x0a        html a href:''; onClick: [\x0a            snap modify: [ :model | model archive ].\x0a            false\x0a        ]; with: 'archive'.\x0a        html with: ' ]'.\x0a        html ul with: [ html trapIter: #((todos)) tag: #li do: [ :each |\x0a            html root empty.\x0a            html input type: 'checkbox'; trap: #('done').\x0a            html span trap: #('done') read: [ :model | html root class: 'done-', model ]; trap: #('text').\x0a        ]].\x0a        html form onSubmit: [\x0a            snap modify: [ :model | model addTodo ].\x0a            false\x0a        ]; with: [\x0a            html input type: 'text'; trap: #((todoText)); at: 'size' put: 30; placeholder: 'add new todo here'.\x0a            html input class: 'btn-primary'; type: 'submit'; value: 'add'.\x0a        ].\x0a    ].\x0a\x09html p trapGuard: #((todos) (isNil)) contents: 'Loading ...'.\x0a\x09]",
+messageSends: ["trapDescend:", "trap:", "h2", "trapGuard:contents:", "div", "span", "with:", "href:", "a", "onClick:", "modify:", "archive", "ul", "trapIter:tag:do:", "empty", "root", "type:", "input", "trap:read:", "class:", ",", "onSubmit:", "form", "addTodo", "at:put:", "placeholder:", "value:", "p"],
 referencedClasses: []
 }),
 smalltalk.AppView);

+ 43 - 43
lib/js/Trapped-Frontend.js

@@ -796,49 +796,6 @@ referencedClasses: ["Trapped"]
 }),
 smalltalk.HTMLCanvas);
 
-smalltalk.addMethod(
-smalltalk.method({
-selector: "guard:trap:contents:",
-category: '*Trapped-Frontend',
-fn: function (anArray,anotherArray,aBlock){
-var self=this;
-var shown,snap;
-return smalltalk.withContext(function($ctx1) { 
-var $1,$2,$3;
-shown=nil;
-_st(anotherArray)._trapDescend_((function(aSnap){
-return smalltalk.withContext(function($ctx2) {
-snap=aSnap;
-return snap;
-}, function($ctx2) {$ctx2.fillBlock({aSnap:aSnap},$ctx1,1)})}));
-self._trap_read_(anArray,(function(gdata){
-return smalltalk.withContext(function($ctx2) {
-$1=_st(shown).__eq(gdata);
-if(! smalltalk.assert($1)){
-shown=gdata;
-shown;
-$2=shown;
-if(smalltalk.assert($2)){
-_st(snap)._do_((function(){
-return smalltalk.withContext(function($ctx3) {
-return self._contents_(aBlock);
-}, function($ctx3) {$ctx3.fillBlock({},$ctx2,5)})}));
-$3=self._asJQuery();
-$ctx2.sendIdx["asJQuery"]=1;
-return _st($3)._show();
-} else {
-return _st(self._asJQuery())._hide();
-};
-};
-}, function($ctx2) {$ctx2.fillBlock({gdata:gdata},$ctx1,2)})}));
-return self}, function($ctx1) {$ctx1.fill(self,"guard:trap:contents:",{anArray:anArray,anotherArray:anotherArray,aBlock:aBlock,shown:shown,snap:snap},smalltalk.TagBrush)})},
-args: ["anArray", "anotherArray", "aBlock"],
-source: "guard: anArray trap: anotherArray contents: aBlock\x0a    | shown snap |\x0a    shown := nil.\x0a\x09anotherArray trapDescend: [ :aSnap | snap := aSnap ].\x0a    self trap: anArray read: [ :gdata |\x0a        shown = gdata ifFalse: [\x0a            shown := gdata.\x0a            shown\x0a\x09\x09\x09\x09ifTrue: [ snap do: [ self contents: aBlock ]. self asJQuery show ]\x0a\x09\x09\x09\x09ifFalse: [ self asJQuery hide ] ]\x0a    ]",
-messageSends: ["trapDescend:", "trap:read:", "ifFalse:", "=", "ifTrue:ifFalse:", "do:", "contents:", "show", "asJQuery", "hide"],
-referencedClasses: []
-}),
-smalltalk.TagBrush);
-
 smalltalk.addMethod(
 smalltalk.method({
 selector: "trap:",
@@ -890,4 +847,47 @@ referencedClasses: ["KeyedPubSubUnsubscribe"]
 }),
 smalltalk.TagBrush);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "trapGuard:contents:",
+category: '*Trapped-Frontend',
+fn: function (anArray,aBlock){
+var self=this;
+var shown,snap;
+return smalltalk.withContext(function($ctx1) { 
+var $1,$2,$3;
+shown=nil;
+[]._trapDescend_((function(aSnap){
+return smalltalk.withContext(function($ctx2) {
+snap=aSnap;
+return snap;
+}, function($ctx2) {$ctx2.fillBlock({aSnap:aSnap},$ctx1,1)})}));
+self._trap_read_(anArray,(function(gdata){
+return smalltalk.withContext(function($ctx2) {
+$1=_st(shown).__eq(gdata);
+if(! smalltalk.assert($1)){
+shown=gdata;
+shown;
+$2=shown;
+if(smalltalk.assert($2)){
+_st(snap)._do_((function(){
+return smalltalk.withContext(function($ctx3) {
+return self._contents_(aBlock);
+}, function($ctx3) {$ctx3.fillBlock({},$ctx2,5)})}));
+$3=self._asJQuery();
+$ctx2.sendIdx["asJQuery"]=1;
+return _st($3)._show();
+} else {
+return _st(self._asJQuery())._hide();
+};
+};
+}, function($ctx2) {$ctx2.fillBlock({gdata:gdata},$ctx1,2)})}));
+return self}, function($ctx1) {$ctx1.fill(self,"trapGuard:contents:",{anArray:anArray,aBlock:aBlock,shown:shown,snap:snap},smalltalk.TagBrush)})},
+args: ["anArray", "aBlock"],
+source: "trapGuard: anArray contents: aBlock\x0a    | shown snap |\x0a    shown := nil.\x0a\x09#() trapDescend: [ :aSnap | snap := aSnap ].\x0a    self trap: anArray read: [ :gdata |\x0a        shown = gdata ifFalse: [\x0a            shown := gdata.\x0a            shown\x0a\x09\x09\x09\x09ifTrue: [ snap do: [ self contents: aBlock ]. self asJQuery show ]\x0a\x09\x09\x09\x09ifFalse: [ self asJQuery hide ] ]\x0a    ]",
+messageSends: ["trapDescend:", "trap:read:", "ifFalse:", "=", "ifTrue:ifFalse:", "do:", "contents:", "show", "asJQuery", "hide"],
+referencedClasses: []
+}),
+smalltalk.TagBrush);
+
 });

+ 2 - 2
lib/st/Trapped-Demo.st

@@ -150,7 +150,7 @@ Widget subclass: #AppView
 renderOn: html
     #() trapDescend: [ :snap |
 	html h2 trap: #((title)).
-    html div guard: #((todos) (notNil)) trap: #() contents: [
+    html div trapGuard: #((todos) (notNil)) contents: [
         html span trap:#((remaining)).
         html with: ' of '.
         html span trap: #((todos) (size)).
@@ -173,7 +173,7 @@ renderOn: html
             html input class: 'btn-primary'; type: 'submit'; value: 'add'.
         ].
     ].
-	html p guard: #((todos) (isNil)) trap: #() contents: 'Loading ...'.
+	html p trapGuard: #((todos) (isNil)) contents: 'Loading ...'.
 	]
 ! !
 

+ 13 - 13
lib/st/Trapped-Frontend.st

@@ -275,19 +275,6 @@ trapIter: path tag: aSymbol do: aBlock
 
 !TagBrush methodsFor: '*Trapped-Frontend'!
 
-guard: anArray trap: anotherArray contents: aBlock
-    | shown snap |
-    shown := nil.
-	anotherArray trapDescend: [ :aSnap | snap := aSnap ].
-    self trap: anArray read: [ :gdata |
-        shown = gdata ifFalse: [
-            shown := gdata.
-            shown
-				ifTrue: [ snap do: [ self contents: aBlock ]. self asJQuery show ]
-				ifFalse: [ self asJQuery hide ] ]
-    ]
-!
-
 trap: path
 	(Trapped current binder: self) installFor: path
 !
@@ -299,5 +286,18 @@ trap: path read: aBlock
         	snap do: [ self with: [ :html | aBlock value: data value: html ] ]
     	]
     ]
+!
+
+trapGuard: anArray contents: aBlock
+    | shown snap |
+    shown := nil.
+	#() trapDescend: [ :aSnap | snap := aSnap ].
+    self trap: anArray read: [ :gdata |
+        shown = gdata ifFalse: [
+            shown := gdata.
+            shown
+				ifTrue: [ snap do: [ self contents: aBlock ]. self asJQuery show ]
+				ifFalse: [ self asJQuery hide ] ]
+    ]
 ! !