Sfoglia il codice sorgente

trapIter: without tag:

Herbert Vojčík 10 anni fa
parent
commit
435ae1714e
5 ha cambiato i file con 64 aggiunte e 58 eliminazioni
  1. 2 1
      README.md
  2. 18 14
      js/Trapped-Demo.js
  3. 30 30
      js/Trapped-Frontend.js
  4. 6 5
      st/Trapped-Demo.st
  5. 8 8
      st/Trapped-Frontend.st

+ 2 - 1
README.md

@@ -59,7 +59,8 @@ The entity wraps any object (via `model:`, as seen in `App >> initialize`).
 The view is subclass of plain `Widget`, but inside it, uses of `trap:`
 (and others of  `trap:xxx:` family) on `TagBrush`
 and `path trapDescend: block` allows you to bind data from view model.
-You can also iterate arrays in the model using `HTMLCanvas >> trapIter:tag:do:`.
+You can also iterate arrays in the model using `HTMLCanvas >> trapIter:do:`
+or `TagBrush >> trapIter:after:`.
 
 To see viewmodel->view update working, try this in Workspace:
 

+ 18 - 14
js/Trapped-Demo.js

@@ -277,27 +277,31 @@ _st(html)._with_(" ]");
 $ctx3.sendIdx["with:"]=4;
 _st(_st(html)._ul())._with_((function(){
 return smalltalk.withContext(function($ctx4) {
-return _st(html)._trapIter_tag_do_([["todos"]],"li",(function(each){
+return _st(html)._trapIter_do_([["todos"]],(function(each){
 return smalltalk.withContext(function($ctx5) {
+return _st(_st(html)._li())._trap_read_([],(function(){
+return smalltalk.withContext(function($ctx6) {
 $5=_st(html)._root();
-$ctx5.sendIdx["root"]=1;
+$ctx6.sendIdx["root"]=1;
 _st($5)._empty();
 $6=_st(html)._input();
-$ctx5.sendIdx["input"]=1;
+$ctx6.sendIdx["input"]=1;
 _st($6)._type_("checkbox");
-$ctx5.sendIdx["type:"]=1;
+$ctx6.sendIdx["type:"]=1;
 $7=_st($6)._trap_(["done"]);
-$ctx5.sendIdx["trap:"]=4;
+$ctx6.sendIdx["trap:"]=4;
 $7;
 $8=_st(html)._span();
 _st($8)._trap_read_(["done"],(function(model){
-return smalltalk.withContext(function($ctx6) {
+return smalltalk.withContext(function($ctx7) {
 return _st(_st(html)._root())._class_("done-".__comma(model));
-$ctx6.sendIdx["class:"]=1;
-}, function($ctx6) {$ctx6.fillBlock({model:model},$ctx5,7)})}));
+$ctx7.sendIdx["class:"]=1;
+}, function($ctx7) {$ctx7.fillBlock({model:model},$ctx6,8)})}));
 $9=_st($8)._trap_(["text"]);
-$ctx5.sendIdx["trap:"]=5;
+$ctx6.sendIdx["trap:"]=5;
 return $9;
+}, function($ctx6) {$ctx6.fillBlock({},$ctx5,7)})}));
+$ctx5.sendIdx["trap:read:"]=1;
 }, function($ctx5) {$ctx5.fillBlock({each:each},$ctx4,6)})}));
 }, function($ctx4) {$ctx4.fillBlock({},$ctx3,5)})}));
 $ctx3.sendIdx["with:"]=5;
@@ -307,9 +311,9 @@ return smalltalk.withContext(function($ctx4) {
 _st(snap)._modify_((function(model){
 return smalltalk.withContext(function($ctx5) {
 return _st(model)._addTodo();
-}, function($ctx5) {$ctx5.fillBlock({model:model},$ctx4,9)})}));
+}, function($ctx5) {$ctx5.fillBlock({model:model},$ctx4,10)})}));
 return false;
-}, function($ctx4) {$ctx4.fillBlock({},$ctx3,8)})}));
+}, function($ctx4) {$ctx4.fillBlock({},$ctx3,9)})}));
 $11=_st($10)._with_((function(){
 return smalltalk.withContext(function($ctx4) {
 $12=_st(html)._input();
@@ -325,7 +329,7 @@ _st($14)._class_("btn-primary");
 _st($14)._type_("submit");
 $15=_st($14)._value_("add");
 return $15;
-}, function($ctx4) {$ctx4.fillBlock({},$ctx3,10)})}));
+}, function($ctx4) {$ctx4.fillBlock({},$ctx3,11)})}));
 return $11;
 }, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)})}));
 $ctx2.sendIdx["trapGuard:contents:"]=1;
@@ -333,8 +337,8 @@ 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 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"],
+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\x09\x09html ul with: [ html trapIter: #((todos)) do: [ :each |\x0a\x09\x09\x09html li trap: #() read: [\x0a\x09\x09\x09\x09html root empty.\x0a\x09\x09\x09\x09html input type: 'checkbox'; trap: #('done').\x0a\x09\x09\x09\x09html span trap: #('done') read: [ :model | html root class: 'done-', model ]; trap: #('text').\x0a\x09\x09]]].\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:do:", "trap:read:", "li", "empty", "root", "type:", "input", "class:", ",", "onSubmit:", "form", "addTodo", "at:put:", "placeholder:", "value:", "p"],
 referencedClasses: []
 }),
 smalltalk.AppView);

+ 30 - 30
js/Trapped-Frontend.js

@@ -490,35 +490,35 @@ smalltalk.Trapped);
 
 smalltalk.addMethod(
 smalltalk.method({
-selector: "envelope:loop:before:tag:do:",
+selector: "envelope:loop:before:do:",
 category: 'private',
-fn: function (envelope,model,endjq,aSymbol,aBlock){
+fn: function (envelope,model,endjq,aBlock){
 var self=this;
 var envjq;
 return smalltalk.withContext(function($ctx1) { 
 envjq=_st(envelope)._asJQuery();
 _st(model)._withIndexDo_((function(item,i){
 return smalltalk.withContext(function($ctx2) {
-_st(envelope)._with_((function(html){
+_st([i])._trapDescend_((function(){
 return smalltalk.withContext(function($ctx3) {
-return _st(_st(html)._perform_(aSymbol))._trap_read_([i],aBlock);
-}, function($ctx3) {$ctx3.fillBlock({html:html},$ctx2,2)})}));
+return _st(envelope)._with_(aBlock);
+}, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)})}));
 return _st(_st(_st(envjq)._children())._detach())._insertBefore_(endjq);
 }, function($ctx2) {$ctx2.fillBlock({item:item,i:i},$ctx1,1)})}));
 _st(envjq)._remove();
-return self}, function($ctx1) {$ctx1.fill(self,"envelope:loop:before:tag:do:",{envelope:envelope,model:model,endjq:endjq,aSymbol:aSymbol,aBlock:aBlock,envjq:envjq},smalltalk.Trapped.klass)})},
-args: ["envelope", "model", "endjq", "aSymbol", "aBlock"],
-source: "envelope: envelope loop: model before: endjq tag: aSymbol do: aBlock\x0a   \x09| envjq |\x0a    envjq := envelope asJQuery.\x0a    model withIndexDo: [ :item :i |\x0a        envelope with: [ :html | (html perform: aSymbol) trap: {i} read: aBlock ].\x0a        envjq children detach insertBefore: endjq.\x0a    ].\x0a    envjq remove",
-messageSends: ["asJQuery", "withIndexDo:", "with:", "trap:read:", "perform:", "insertBefore:", "detach", "children", "remove"],
+return self}, function($ctx1) {$ctx1.fill(self,"envelope:loop:before:do:",{envelope:envelope,model:model,endjq:endjq,aBlock:aBlock,envjq:envjq},smalltalk.Trapped.klass)})},
+args: ["envelope", "model", "endjq", "aBlock"],
+source: "envelope: envelope loop: model before: endjq do: aBlock\x0a   \x09| envjq |\x0a    envjq := envelope asJQuery.\x0a    model withIndexDo: [ :item :i |\x0a        {i} trapDescend: [ envelope with: aBlock ].\x0a        envjq children detach insertBefore: endjq.\x0a    ].\x0a    envjq remove",
+messageSends: ["asJQuery", "withIndexDo:", "trapDescend:", "with:", "insertBefore:", "detach", "children", "remove"],
 referencedClasses: []
 }),
 smalltalk.Trapped.klass);
 
 smalltalk.addMethod(
 smalltalk.method({
-selector: "loop:between:and:tag:do:",
+selector: "loop:between:and:do:",
 category: 'private',
-fn: function (model,start,end,aSymbol,aBlock){
+fn: function (model,start,end,aBlock){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
 var $2,$1;
@@ -531,13 +531,13 @@ return smalltalk.withContext(function($ctx2) {
 if(($receiver = model) == nil || $receiver == null){
 return model;
 } else {
-return self._envelope_loop_before_tag_do_(_st(html)._div(),model,_st(end)._asJQuery(),aSymbol,aBlock);
+return self._envelope_loop_before_do_(_st(html)._div(),model,_st(end)._asJQuery(),aBlock);
 };
 }, function($ctx2) {$ctx2.fillBlock({html:html},$ctx1,1)})}));
-return self}, function($ctx1) {$ctx1.fill(self,"loop:between:and:tag:do:",{model:model,start:start,end:end,aSymbol:aSymbol,aBlock:aBlock},smalltalk.Trapped.klass)})},
-args: ["model", "start", "end", "aSymbol", "aBlock"],
-source: "loop: model between: start and: end tag: aSymbol do: aBlock\x0a    (start asJQuery nextUntil: end element) remove.\x0a    start with: [ :html | model ifNotNil: [\x0a    \x09self envelope: html div loop: model before: end asJQuery tag: aSymbol do: aBlock\x0a\x09]]",
-messageSends: ["remove", "nextUntil:", "asJQuery", "element", "with:", "ifNotNil:", "envelope:loop:before:tag:do:", "div"],
+return self}, function($ctx1) {$ctx1.fill(self,"loop:between:and:do:",{model:model,start:start,end:end,aBlock:aBlock},smalltalk.Trapped.klass)})},
+args: ["model", "start", "end", "aBlock"],
+source: "loop: model between: start and: end do: aBlock\x0a    (start asJQuery nextUntil: end element) remove.\x0a    start with: [ :html | model ifNotNil: [\x0a    \x09self envelope: html div loop: model before: end asJQuery do: aBlock\x0a\x09]]",
+messageSends: ["remove", "nextUntil:", "asJQuery", "element", "with:", "ifNotNil:", "envelope:loop:before:do:", "div"],
 referencedClasses: []
 }),
 smalltalk.Trapped.klass);
@@ -769,19 +769,19 @@ smalltalk.Array);
 
 smalltalk.addMethod(
 smalltalk.method({
-selector: "trapIter:tag:do:",
+selector: "trapIter:do:",
 category: '*Trapped-Frontend',
-fn: function (path,aSymbol,aBlock){
+fn: function (path,aBlock){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
 self._with_((function(html){
 return smalltalk.withContext(function($ctx2) {
-return _st(_st(html)._noscript())._trapIter_tag_after_(path,aSymbol,aBlock);
+return _st(_st(html)._noscript())._trapIter_after_(path,aBlock);
 }, function($ctx2) {$ctx2.fillBlock({html:html},$ctx1,1)})}));
-return self}, function($ctx1) {$ctx1.fill(self,"trapIter:tag:do:",{path:path,aSymbol:aSymbol,aBlock:aBlock},smalltalk.HTMLCanvas)})},
-args: ["path", "aSymbol", "aBlock"],
-source: "trapIter: path tag: aSymbol do: aBlock\x0a    self with: [ :html | html noscript trapIter: path tag: aSymbol after: aBlock ]",
-messageSends: ["with:", "trapIter:tag:after:", "noscript"],
+return self}, function($ctx1) {$ctx1.fill(self,"trapIter:do:",{path:path,aBlock:aBlock},smalltalk.HTMLCanvas)})},
+args: ["path", "aBlock"],
+source: "trapIter: path do: aBlock\x0a    self with: [ :html | html noscript trapIter: path after: aBlock ]",
+messageSends: ["with:", "trapIter:after:", "noscript"],
 referencedClasses: []
 }),
 smalltalk.HTMLCanvas);
@@ -891,9 +891,9 @@ smalltalk.TagBrush);
 
 smalltalk.addMethod(
 smalltalk.method({
-selector: "trapIter:tag:after:",
+selector: "trapIter:after:",
 category: '*Trapped-Frontend',
-fn: function (path,aSymbol,aBlock){
+fn: function (path,aBlock){
 var self=this;
 var end;
 function $TagBrush(){return smalltalk.TagBrush||(typeof TagBrush=="undefined"?nil:TagBrush)}
@@ -906,12 +906,12 @@ $1=_st($2)._insertAfter_(self._asJQuery());
 end=_st($TagBrush())._fromJQuery_canvas_($1,self["@canvas"]);
 self._trap_read_(path,(function(model){
 return smalltalk.withContext(function($ctx2) {
-return _st($Trapped())._loop_between_and_tag_do_(model,self,end,aSymbol,aBlock);
+return _st($Trapped())._loop_between_and_do_(model,self,end,aBlock);
 }, function($ctx2) {$ctx2.fillBlock({model:model},$ctx1,1)})}));
-return self}, function($ctx1) {$ctx1.fill(self,"trapIter:tag:after:",{path:path,aSymbol:aSymbol,aBlock:aBlock,end:end},smalltalk.TagBrush)})},
-args: ["path", "aSymbol", "aBlock"],
-source: "trapIter: path tag: aSymbol after: aBlock\x0a\x09| end |\x0a\x09end := TagBrush fromJQuery: ('<noscript />' asJQuery insertAfter: self asJQuery) canvas: canvas.\x0a    self trap: path read: [ :model |\x0a    \x09Trapped loop: model between: self and: end tag: aSymbol do: aBlock.\x0a    ]",
-messageSends: ["fromJQuery:canvas:", "insertAfter:", "asJQuery", "trap:read:", "loop:between:and:tag:do:"],
+return self}, function($ctx1) {$ctx1.fill(self,"trapIter:after:",{path:path,aBlock:aBlock,end:end},smalltalk.TagBrush)})},
+args: ["path", "aBlock"],
+source: "trapIter: path after: aBlock\x0a\x09| end |\x0a\x09end := TagBrush fromJQuery: ('<noscript />' asJQuery insertAfter: self asJQuery) canvas: canvas.\x0a    self trap: path read: [ :model |\x0a    \x09Trapped loop: model between: self and: end do: aBlock.\x0a    ]",
+messageSends: ["fromJQuery:canvas:", "insertAfter:", "asJQuery", "trap:read:", "loop:between:and:do:"],
 referencedClasses: ["TagBrush", "Trapped"]
 }),
 smalltalk.TagBrush);

+ 6 - 5
st/Trapped-Demo.st

@@ -160,11 +160,12 @@ renderOn: html
             false
         ]; with: 'archive'.
         html with: ' ]'.
-        html ul with: [ html trapIter: #((todos)) tag: #li do: [ :each |
-            html root empty.
-            html input type: 'checkbox'; trap: #('done').
-            html span trap: #('done') read: [ :model | html root class: 'done-', model ]; trap: #('text').
-        ]].
+		html ul with: [ html trapIter: #((todos)) do: [ :each |
+			html li trap: #() read: [
+				html root empty.
+				html input type: 'checkbox'; trap: #('done').
+				html span trap: #('done') read: [ :model | html root class: 'done-', model ]; trap: #('text').
+		]]].
         html form onSubmit: [
             snap modify: [ :model | model addTodo ].
             false

+ 8 - 8
st/Trapped-Frontend.st

@@ -181,20 +181,20 @@ parse: anArray
 
 !Trapped class methodsFor: 'private'!
 
-envelope: envelope loop: model before: endjq tag: aSymbol do: aBlock
+envelope: envelope loop: model before: endjq do: aBlock
    	| envjq |
     envjq := envelope asJQuery.
     model withIndexDo: [ :item :i |
-        envelope with: [ :html | (html perform: aSymbol) trap: {i} read: aBlock ].
+        {i} trapDescend: [ envelope with: aBlock ].
         envjq children detach insertBefore: endjq.
     ].
     envjq remove
 !
 
-loop: model between: start and: end tag: aSymbol do: aBlock
+loop: model between: start and: end do: aBlock
     (start asJQuery nextUntil: end element) remove.
     start with: [ :html | model ifNotNil: [
-    	self envelope: html div loop: model before: end asJQuery tag: aSymbol do: aBlock
+    	self envelope: html div loop: model before: end asJQuery do: aBlock
 	]]
 ! !
 
@@ -265,8 +265,8 @@ trapDescend: aBlock
 
 !HTMLCanvas methodsFor: '*Trapped-Frontend'!
 
-trapIter: path tag: aSymbol do: aBlock
-    self with: [ :html | html noscript trapIter: path tag: aSymbol after: aBlock ]
+trapIter: path do: aBlock
+    self with: [ :html | html noscript trapIter: path after: aBlock ]
 ! !
 
 !TagBrush methodsFor: '*Trapped-Frontend'!
@@ -298,11 +298,11 @@ trapGuard: anArray contents: aBlock
 					ifFalse: [ self asJQuery hide; empty ] ] ] ]
 !
 
-trapIter: path tag: aSymbol after: aBlock
+trapIter: path after: aBlock
 	| end |
 	end := TagBrush fromJQuery: ('<noscript />' asJQuery insertAfter: self asJQuery) canvas: canvas.
     self trap: path read: [ :model |
-    	Trapped loop: model between: self and: end tag: aSymbol do: aBlock.
+    	Trapped loop: model between: self and: end do: aBlock.
     ]
 ! !