Browse Source

asTrapPathOn:, symbols resolved as well.

Herbert Vojčík 12 years ago
parent
commit
424901f7f1
6 changed files with 235 additions and 12 deletions
  1. 81 0
      js/Trapped-Common.deploy.js
  2. 106 0
      js/Trapped-Common.js
  3. 5 3
      js/Trapped-Demo.deploy.js
  4. 9 7
      js/Trapped-Demo.js
  5. 32 0
      st/Trapped-Common.st
  6. 2 2
      st/Trapped-Demo.st

+ 81 - 0
js/Trapped-Common.deploy.js

@@ -164,3 +164,84 @@ return self}
 smalltalk.TrappedModelWrapper.klass);
 
 
+smalltalk.addMethod(
+"_reverseTrapAt_",
+smalltalk.method({
+selector: "reverseTrapAt:",
+fn: function (anObject){
+var self=this;
+return nil;
+}
+}),
+smalltalk.Object);
+
+smalltalk.addMethod(
+"_asTrapPathOn_",
+smalltalk.method({
+selector: "asTrapPathOn:",
+fn: function (anObject){
+var self=this;
+var $1;
+$1=smalltalk.send(self,"_inject_into_",[anObject,(function(soFar,segment){
+if(($receiver = soFar) == nil || $receiver == undefined){
+return soFar;
+} else {
+return smalltalk.send(segment,"_reverseTrapAt_",[soFar]);
+};
+})]);
+return $1;
+}
+}),
+smalltalk.SequenceableCollection);
+
+smalltalk.addMethod(
+"_reverseTrapAt_",
+smalltalk.method({
+selector: "reverseTrapAt:",
+fn: function (anObject){
+var self=this;
+var $1;
+$1=smalltalk.send(anObject,"_at_ifAbsent_",[self,(function(){
+return nil;
+})]);
+return $1;
+}
+}),
+smalltalk.String);
+
+smalltalk.addMethod(
+"_reverseTrapAt_",
+smalltalk.method({
+selector: "reverseTrapAt:",
+fn: function (anObject){
+var self=this;
+var $1;
+var $early={};
+try {
+$1=smalltalk.send((function(){
+return smalltalk.send(anObject,"_perform_",[self]);
+}),"_on_do_",[(smalltalk.MessageNotUnderstood || MessageNotUnderstood),(function(){
+throw $early=[nil];
+})]);
+return $1;
+}
+catch(e) {if(e===$early)return e[0]; throw e}
+}
+}),
+smalltalk.Symbol);
+
+smalltalk.addMethod(
+"_reverseTrapAt_",
+smalltalk.method({
+selector: "reverseTrapAt:",
+fn: function (anObject){
+var self=this;
+var $1;
+$1=smalltalk.send(anObject,"_at_ifAbsent_",[self,(function(){
+return nil;
+})]);
+return $1;
+}
+}),
+smalltalk.Number);
+

+ 106 - 0
js/Trapped-Common.js

@@ -221,3 +221,109 @@ referencedClasses: []
 smalltalk.TrappedModelWrapper.klass);
 
 
+smalltalk.addMethod(
+"_reverseTrapAt_",
+smalltalk.method({
+selector: "reverseTrapAt:",
+category: '*Trapped-Common',
+fn: function (anObject){
+var self=this;
+return nil;
+},
+args: ["anObject"],
+source: "reverseTrapAt: anObject\x0a\x09^nil",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.Object);
+
+smalltalk.addMethod(
+"_asTrapPathOn_",
+smalltalk.method({
+selector: "asTrapPathOn:",
+category: '*Trapped-Common',
+fn: function (anObject){
+var self=this;
+var $1;
+$1=smalltalk.send(self,"_inject_into_",[anObject,(function(soFar,segment){
+if(($receiver = soFar) == nil || $receiver == undefined){
+return soFar;
+} else {
+return smalltalk.send(segment,"_reverseTrapAt_",[soFar]);
+};
+})]);
+return $1;
+},
+args: ["anObject"],
+source: "asTrapPathOn: anObject\x0a    ^ self inject: anObject into: [ :soFar :segment |\x0a        soFar ifNotNil: [ segment reverseTrapAt: soFar ]\x0a    ]",
+messageSends: ["inject:into:", "ifNotNil:", "reverseTrapAt:"],
+referencedClasses: []
+}),
+smalltalk.SequenceableCollection);
+
+smalltalk.addMethod(
+"_reverseTrapAt_",
+smalltalk.method({
+selector: "reverseTrapAt:",
+category: '*Trapped-Common',
+fn: function (anObject){
+var self=this;
+var $1;
+$1=smalltalk.send(anObject,"_at_ifAbsent_",[self,(function(){
+return nil;
+})]);
+return $1;
+},
+args: ["anObject"],
+source: "reverseTrapAt: anObject\x0a\x09^anObject at: self ifAbsent: [nil]",
+messageSends: ["at:ifAbsent:"],
+referencedClasses: []
+}),
+smalltalk.String);
+
+smalltalk.addMethod(
+"_reverseTrapAt_",
+smalltalk.method({
+selector: "reverseTrapAt:",
+category: '*Trapped-Common',
+fn: function (anObject){
+var self=this;
+var $1;
+var $early={};
+try {
+$1=smalltalk.send((function(){
+return smalltalk.send(anObject,"_perform_",[self]);
+}),"_on_do_",[(smalltalk.MessageNotUnderstood || MessageNotUnderstood),(function(){
+throw $early=[nil];
+})]);
+return $1;
+}
+catch(e) {if(e===$early)return e[0]; throw e}
+},
+args: ["anObject"],
+source: "reverseTrapAt: anObject\x0a\x09^[anObject perform: self] on: MessageNotUnderstood do: [^nil]",
+messageSends: ["on:do:", "perform:"],
+referencedClasses: ["MessageNotUnderstood"]
+}),
+smalltalk.Symbol);
+
+smalltalk.addMethod(
+"_reverseTrapAt_",
+smalltalk.method({
+selector: "reverseTrapAt:",
+category: '*Trapped-Common',
+fn: function (anObject){
+var self=this;
+var $1;
+$1=smalltalk.send(anObject,"_at_ifAbsent_",[self,(function(){
+return nil;
+})]);
+return $1;
+},
+args: ["anObject"],
+source: "reverseTrapAt: anObject\x0a\x09^anObject at: self ifAbsent: [nil]",
+messageSends: ["at:ifAbsent:"],
+referencedClasses: []
+}),
+smalltalk.Number);
+

+ 5 - 3
js/Trapped-Demo.deploy.js

@@ -7,6 +7,10 @@ selector: "renderOn:",
 fn: function (html){
 var self=this;
 smalltalk.send(smalltalk.send(html,"_h2",[]),"_trapShow_",[["title"]]);
+smalltalk.send(smalltalk.send(html,"_p",[]),"_with_",[(function(){
+smalltalk.send(smalltalk.send(html,"_span",[]),"_trapShow_",[["items", smalltalk.symbolFor("size")]]);
+return smalltalk.send(html,"_with_",[" item(s)."]);
+})]);
 smalltalk.send(smalltalk.send(html,"_p",[]),"_trapShow_",[["items"]]);
 return self}
 }),
@@ -71,9 +75,7 @@ selector: "read:do:",
 fn: function (path,aBlock){
 var self=this;
 var data;
-data=smalltalk.send(path,"_inject_into_",[smalltalk.send(self,"_payload",[]),(function(soFar,segment){
-return smalltalk.send(soFar,"_at_",[segment]);
-})]);
+data=smalltalk.send(path,"_asTrapPathOn_",[smalltalk.send(self,"_payload",[])]);
 smalltalk.send(aBlock,"_value_",[data]);
 return self}
 }),

+ 9 - 7
js/Trapped-Demo.js

@@ -8,11 +8,15 @@ category: 'rendering',
 fn: function (html){
 var self=this;
 smalltalk.send(smalltalk.send(html,"_h2",[]),"_trapShow_",[["title"]]);
+smalltalk.send(smalltalk.send(html,"_p",[]),"_with_",[(function(){
+smalltalk.send(smalltalk.send(html,"_span",[]),"_trapShow_",[["items", smalltalk.symbolFor("size")]]);
+return smalltalk.send(html,"_with_",[" item(s)."]);
+})]);
 smalltalk.send(smalltalk.send(html,"_p",[]),"_trapShow_",[["items"]]);
 return self},
 args: ["html"],
-source: "renderOn: html\x0a\x09html h2 trapShow: #('title').\x0a\x09html p trapShow: #('items')",
-messageSends: ["trapShow:", "h2", "p"],
+source: "renderOn: html\x0a\x09html h2 trapShow: #('title').\x0a    html p with: [ html span trapShow: #('items' #size). html with: ' item(s).' ].\x0a\x09html p trapShow: #('items')",
+messageSends: ["trapShow:", "h2", "with:", "span", "p"],
 referencedClasses: []
 }),
 smalltalk.AppView);
@@ -97,14 +101,12 @@ category: 'action',
 fn: function (path,aBlock){
 var self=this;
 var data;
-data=smalltalk.send(path,"_inject_into_",[smalltalk.send(self,"_payload",[]),(function(soFar,segment){
-return smalltalk.send(soFar,"_at_",[segment]);
-})]);
+data=smalltalk.send(path,"_asTrapPathOn_",[smalltalk.send(self,"_payload",[])]);
 smalltalk.send(aBlock,"_value_",[data]);
 return self},
 args: ["path", "aBlock"],
-source: "read: path do: aBlock\x0a\x09| data |\x0a    data := path inject: self payload\x0a    \x09into: [ :soFar :segment | soFar at: segment ].\x0a\x09aBlock value: data.",
-messageSends: ["inject:into:", "payload", "at:", "value:"],
+source: "read: path do: aBlock\x0a\x09| data |\x0a    data := path asTrapPathOn: self payload.\x0a\x09aBlock value: data.",
+messageSends: ["asTrapPathOn:", "payload", "value:"],
 referencedClasses: []
 }),
 smalltalk.TrappedPlainModel);

+ 32 - 0
st/Trapped-Common.st

@@ -94,3 +94,35 @@ start
 	self new start
 ! !
 
+!Object methodsFor: '*Trapped-Common'!
+
+reverseTrapAt: anObject
+	^nil
+! !
+
+!SequenceableCollection methodsFor: '*Trapped-Common'!
+
+asTrapPathOn: anObject
+    ^ self inject: anObject into: [ :soFar :segment |
+        soFar ifNotNil: [ segment reverseTrapAt: soFar ]
+    ]
+! !
+
+!String methodsFor: '*Trapped-Common'!
+
+reverseTrapAt: anObject
+	^anObject at: self ifAbsent: [nil]
+! !
+
+!Symbol methodsFor: '*Trapped-Common'!
+
+reverseTrapAt: anObject
+	^[anObject perform: self] on: MessageNotUnderstood do: [^nil]
+! !
+
+!Number methodsFor: '*Trapped-Common'!
+
+reverseTrapAt: anObject
+	^anObject at: self ifAbsent: [nil]
+! !
+

+ 2 - 2
st/Trapped-Demo.st

@@ -7,6 +7,7 @@ Widget subclass: #AppView
 
 renderOn: html
 	html h2 trapShow: #('title').
+    html p with: [ html span trapShow: #('items' #size). html with: ' item(s).' ].
 	html p trapShow: #('items')
 ! !
 
@@ -41,8 +42,7 @@ TrappedModelWrapper subclass: #TrappedPlainModel
 
 read: path do: aBlock
 	| data |
-    data := path inject: self payload
-    	into: [ :soFar :segment | soFar at: segment ].
+    data := path asTrapPathOn: self payload.
 	aBlock value: data.
 ! !