Преглед изворни кода

ad hoc model->view processor creating facility

Herbert Vojčík пре 11 година
родитељ
комит
7717fc4d37
6 измењених фајлова са 150 додато и 19 уклоњено
  1. 35 18
      js/Trapped-Demo.js
  2. 19 0
      js/Trapped-Frontend.js
  3. 57 0
      js/Trapped-Processors.js
  4. 9 1
      st/Trapped-Demo.st
  5. 4 0
      st/Trapped-Frontend.st
  6. 26 0
      st/Trapped-Processors.st

+ 35 - 18
js/Trapped-Demo.js

@@ -1,4 +1,4 @@
-define("gh_herby_trapped/Trapped-Demo", ["amber_vm/smalltalk", "amber_vm/nil", "amber_vm/_st", "gh_herby_trapped/Trapped-Backend", "amber_core/Kernel-Objects", "amber_core/Canvas"], function(smalltalk,nil,_st){
+define("gh_herby_trapped/Trapped-Demo", ["amber_vm/smalltalk", "amber_vm/nil", "amber_vm/_st", "gh_herby_trapped/Trapped-Backend", "amber_core/Kernel-Objects", "amber_core/Canvas", "gh_herby_trapped/Trapped-Frontend"], function(smalltalk,nil,_st){
 smalltalk.addPackage('Trapped-Demo');
 smalltalk.packages["Trapped-Demo"].transport = {"type":"amd","amdNamespace":"gh_herby_trapped"};
 
@@ -240,31 +240,48 @@ category: 'rendering',
 fn: function (html){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
-var $1,$2,$3,$4,$5;
+var $1,$2,$3,$4;
 _st(html)._trapIter_tag_do_([],"li",(function(each){
 return smalltalk.withContext(function($ctx2) {
-$1=_st(html)._root();
-$ctx2.sendIdx["root"]=1;
-_st($1)._empty();
-$2=_st(html)._input();
-_st($2)._type_("checkbox");
-$3=_st($2)._trap_processors_(["done"],["inputChecked"]);
-$3;
-$4=_st(html)._span();
-_st($4)._trap_read_(["done"],(function(model){
-return smalltalk.withContext(function($ctx3) {
-return _st(_st(html)._root())._class_("done-".__comma(model));
-}, function($ctx3) {$ctx3.fillBlock({model:model},$ctx2,2)})}));
-$5=_st($4)._trap_(["text"]);
-return $5;
+_st(_st(html)._root())._empty();
+$1=_st(html)._input();
+_st($1)._type_("checkbox");
+$2=_st($1)._trap_processors_(["done"],["inputChecked"]);
+$ctx2.sendIdx["trap:processors:"]=1;
+$2;
+$3=_st(html)._span();
+_st($3)._trap_processors_(["done"],["classDoneXxx"]);
+$4=_st($3)._trap_(["text"]);
+return $4;
 }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
 return self}, function($ctx1) {$ctx1.fill(self,"renderOn:",{html:html},smalltalk.TodoItemsWidget)})},
 args: ["html"],
-source: "renderOn: html\x0a\x09html trapIter: #() tag: #li do: [ :each |\x0a\x09\x09html root empty.\x0a\x09\x09html input type: 'checkbox'; trap: #('done') processors: #(inputChecked).\x0a\x09\x09html span trap: #('done') read: [ :model | html root class: 'done-', model ]; trap: #('text').\x0a\x09]",
-messageSends: ["trapIter:tag:do:", "empty", "root", "type:", "input", "trap:processors:", "trap:read:", "span", "class:", ",", "trap:"],
+source: "renderOn: html\x0a\x09html trapIter: #() tag: #li do: [ :each |\x0a\x09\x09html root empty.\x0a\x09\x09html input type: 'checkbox'; trap: #('done') processors: #(inputChecked).\x0a\x09\x09html span\x0a\x09\x09\x09trap: #('done') processors: #(classDoneXxx);\x0a\x09\x09\x09trap: #('text')\x0a\x09]",
+messageSends: ["trapIter:tag:do:", "empty", "root", "type:", "input", "trap:processors:", "span", "trap:"],
 referencedClasses: []
 }),
 smalltalk.TodoItemsWidget);
 
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "classDoneXxx",
+category: '*Trapped-Demo',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+var $1;
+$1=self._dataToView_((function(carrier){
+return smalltalk.withContext(function($ctx2) {
+return _st(_st(carrier)._target())._class_("done-".__comma(_st(carrier)._value()));
+}, function($ctx2) {$ctx2.fillBlock({carrier:carrier},$ctx1,1)})}));
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"classDoneXxx",{},smalltalk.TrappedProcessor.klass)})},
+args: [],
+source: "classDoneXxx\x0a\x09^self dataToView: [ :carrier | carrier target class: 'done-', carrier value ]",
+messageSends: ["dataToView:", "class:", "target", ",", "value"],
+referencedClasses: []
+}),
+smalltalk.TrappedProcessor.klass);
+
 });

+ 19 - 0
js/Trapped-Frontend.js

@@ -485,6 +485,25 @@ referencedClasses: ["TrappedProcessorContents"]
 }),
 smalltalk.TrappedProcessor.klass);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "dataToView:",
+category: 'factory',
+fn: function (aBlock){
+var self=this;
+function $TrappedProcessorDataAdhoc(){return smalltalk.TrappedProcessorDataAdhoc||(typeof TrappedProcessorDataAdhoc=="undefined"?nil:TrappedProcessorDataAdhoc)}
+return smalltalk.withContext(function($ctx1) { 
+var $1;
+$1=_st($TrappedProcessorDataAdhoc())._newToView_(aBlock);
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"dataToView:",{aBlock:aBlock},smalltalk.TrappedProcessor.klass)})},
+args: ["aBlock"],
+source: "dataToView: aBlock\x0a\x09^TrappedProcessorDataAdhoc newToView: aBlock",
+messageSends: ["newToView:"],
+referencedClasses: ["TrappedProcessorDataAdhoc"]
+}),
+smalltalk.TrappedProcessor.klass);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "guardContents:",

+ 57 - 0
js/Trapped-Processors.js

@@ -42,6 +42,63 @@ smalltalk.TrappedProcessorContents);
 
 
 
+smalltalk.addClass('TrappedProcessorDataAdhoc', smalltalk.TrappedDataExpectingProcessor, ['toViewBlock'], 'Trapped-Processors');
+smalltalk.TrappedProcessorDataAdhoc.comment="I put data into target via contents: in toView:";
+smalltalk.addMethod(
+smalltalk.method({
+selector: "toView:",
+category: 'data transformation',
+fn: function (aDataCarrier){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+_st(self["@toViewBlock"])._value_(aDataCarrier);
+return self}, function($ctx1) {$ctx1.fill(self,"toView:",{aDataCarrier:aDataCarrier},smalltalk.TrappedProcessorDataAdhoc)})},
+args: ["aDataCarrier"],
+source: "toView: aDataCarrier\x0a\x09toViewBlock value: aDataCarrier",
+messageSends: ["value:"],
+referencedClasses: []
+}),
+smalltalk.TrappedProcessorDataAdhoc);
+
+smalltalk.addMethod(
+smalltalk.method({
+selector: "toViewBlock:",
+category: 'accessing',
+fn: function (aBlock){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+self["@toViewBlock"]=aBlock;
+return self}, function($ctx1) {$ctx1.fill(self,"toViewBlock:",{aBlock:aBlock},smalltalk.TrappedProcessorDataAdhoc)})},
+args: ["aBlock"],
+source: "toViewBlock: aBlock\x0a\x09toViewBlock := aBlock",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.TrappedProcessorDataAdhoc);
+
+
+smalltalk.addMethod(
+smalltalk.method({
+selector: "newToView:",
+category: 'instance creation',
+fn: function (aBlock){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+var $2,$3,$1;
+$2=self._new();
+_st($2)._toViewBlock_(aBlock);
+$3=_st($2)._yourself();
+$1=$3;
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"newToView:",{aBlock:aBlock},smalltalk.TrappedProcessorDataAdhoc.klass)})},
+args: ["aBlock"],
+source: "newToView: aBlock\x0a\x09^self new\x0a\x09\x09toViewBlock: aBlock;\x0a\x09\x09yourself",
+messageSends: ["toViewBlock:", "new", "yourself"],
+referencedClasses: []
+}),
+smalltalk.TrappedProcessorDataAdhoc.klass);
+
+
 smalltalk.addClass('TrappedProcessorInputChecked', smalltalk.TrappedDataExpectingProcessor, [], 'Trapped-Processors');
 smalltalk.TrappedProcessorInputChecked.comment="I bind to checkbox checked attribute.";
 smalltalk.addMethod(

+ 9 - 1
st/Trapped-Demo.st

@@ -151,7 +151,15 @@ renderOn: html
 	html trapIter: #() tag: #li do: [ :each |
 		html root empty.
 		html input type: 'checkbox'; trap: #('done') processors: #(inputChecked).
-		html span trap: #('done') read: [ :model | html root class: 'done-', model ]; trap: #('text').
+		html span
+			trap: #('done') processors: #(classDoneXxx);
+			trap: #('text')
 	]
 ! !
 
+!TrappedProcessor class methodsFor: '*Trapped-Demo'!
+
+classDoneXxx
+	^self dataToView: [ :carrier | carrier target class: 'done-', carrier value ]
+! !
+

+ 4 - 0
st/Trapped-Frontend.st

@@ -180,6 +180,10 @@ contents
 	^TrappedProcessorContents new
 !
 
+dataToView: aBlock
+	^TrappedProcessorDataAdhoc newToView: aBlock
+!
+
 guardContents: anArray
 	^TrappedProcessorGuardContents new: anArray
 !

+ 26 - 0
st/Trapped-Processors.st

@@ -29,6 +29,32 @@ toView: aDataCarrier
 	aDataCarrier toTargetContents
 ! !
 
+TrappedDataExpectingProcessor subclass: #TrappedProcessorDataAdhoc
+	instanceVariableNames: 'toViewBlock'
+	package: 'Trapped-Processors'!
+!TrappedProcessorDataAdhoc commentStamp!
+I put data into target via contents: in toView:!
+
+!TrappedProcessorDataAdhoc methodsFor: 'accessing'!
+
+toViewBlock: aBlock
+	toViewBlock := aBlock
+! !
+
+!TrappedProcessorDataAdhoc methodsFor: 'data transformation'!
+
+toView: aDataCarrier
+	toViewBlock value: aDataCarrier
+! !
+
+!TrappedProcessorDataAdhoc class methodsFor: 'instance creation'!
+
+newToView: aBlock
+	^self new
+		toViewBlock: aBlock;
+		yourself
+! !
+
 TrappedDataExpectingProcessor subclass: #TrappedProcessorInputChecked
 	instanceVariableNames: ''
 	package: 'Trapped-Processors'!