Browse Source

payload[:], reading from model object

Herbert Vojčík 12 years ago
parent
commit
c1784498db
6 changed files with 186 additions and 14 deletions
  1. 22 0
      js/Trapped-Demo.deploy.js
  2. 32 0
      js/Trapped-Demo.js
  3. 40 4
      js/Trapped-Frontend.deploy.js
  4. 57 6
      js/Trapped-Frontend.js
  5. 12 0
      st/Trapped-Demo.st
  6. 23 4
      st/Trapped-Frontend.st

+ 22 - 0
js/Trapped-Demo.deploy.js

@@ -1,5 +1,16 @@
 smalltalk.addPackage('Trapped-Demo', {});
 smalltalk.addClass('App', smalltalk.TrappedFly, [], 'Trapped-Demo');
+smalltalk.addMethod(
+"_initialize",
+smalltalk.method({
+selector: "initialize",
+fn: function (){
+var self=this;
+smalltalk.send(self,"_payload_",[smalltalk.HashedCollection._fromPairs_([smalltalk.send("items","__minus_gt",[["hello", "world"]])])]);
+return self}
+}),
+smalltalk.App);
+
 
 
 smalltalk.addClass('AppView', smalltalk.Widget, [], 'Trapped-Demo');
@@ -18,6 +29,17 @@ smalltalk.AppView);
 
 
 smalltalk.addClass('Name', smalltalk.TrappedFly, [], 'Trapped-Demo');
+smalltalk.addMethod(
+"_initialize",
+smalltalk.method({
+selector: "initialize",
+fn: function (){
+var self=this;
+smalltalk.send(self,"_payload_",["To-Do List"]);
+return self}
+}),
+smalltalk.Name);
+
 
 
 smalltalk.addClass('NameView', smalltalk.Widget, [], 'Trapped-Demo');

+ 32 - 0
js/Trapped-Demo.js

@@ -1,5 +1,21 @@
 smalltalk.addPackage('Trapped-Demo', {});
 smalltalk.addClass('App', smalltalk.TrappedFly, [], 'Trapped-Demo');
+smalltalk.addMethod(
+"_initialize",
+smalltalk.method({
+selector: "initialize",
+category: 'initialization',
+fn: function (){
+var self=this;
+smalltalk.send(self,"_payload_",[smalltalk.HashedCollection._fromPairs_([smalltalk.send("items","__minus_gt",[["hello", "world"]])])]);
+return self},
+args: [],
+source: "initialize\x0a\x09self payload: #{'items'->#('hello' 'world')}",
+messageSends: ["payload:", "->"],
+referencedClasses: []
+}),
+smalltalk.App);
+
 
 
 smalltalk.addClass('AppView', smalltalk.Widget, [], 'Trapped-Demo');
@@ -23,6 +39,22 @@ smalltalk.AppView);
 
 
 smalltalk.addClass('Name', smalltalk.TrappedFly, [], 'Trapped-Demo');
+smalltalk.addMethod(
+"_initialize",
+smalltalk.method({
+selector: "initialize",
+category: 'initialization',
+fn: function (){
+var self=this;
+smalltalk.send(self,"_payload_",["To-Do List"]);
+return self},
+args: [],
+source: "initialize\x0a\x09self payload: 'To-Do List'",
+messageSends: ["payload:"],
+referencedClasses: []
+}),
+smalltalk.Name);
+
 
 
 smalltalk.addClass('NameView', smalltalk.Widget, [], 'Trapped-Demo');

+ 40 - 4
js/Trapped-Frontend.deploy.js

@@ -1,5 +1,5 @@
 smalltalk.addPackage('Trapped-Frontend', {});
-smalltalk.addClass('TrappedFly', smalltalk.Object, [], 'Trapped-Frontend');
+smalltalk.addClass('TrappedFly', smalltalk.Object, ['payload'], 'Trapped-Frontend');
 smalltalk.addMethod(
 "_name",
 smalltalk.method({
@@ -13,6 +13,28 @@ return $1;
 }),
 smalltalk.TrappedFly);
 
+smalltalk.addMethod(
+"_payload",
+smalltalk.method({
+selector: "payload",
+fn: function (){
+var self=this;
+return self["@payload"];
+}
+}),
+smalltalk.TrappedFly);
+
+smalltalk.addMethod(
+"_payload_",
+smalltalk.method({
+selector: "payload:",
+fn: function (anObject){
+var self=this;
+self["@payload"]=anObject;
+return self}
+}),
+smalltalk.TrappedFly);
+
 smalltalk.addMethod(
 "_start",
 smalltalk.method({
@@ -109,6 +131,21 @@ return self}
 }),
 smalltalk.Trapped);
 
+smalltalk.addMethod(
+"_read_do_",
+smalltalk.method({
+selector: "read:do:",
+fn: function (path,aBlock){
+var self=this;
+var model;
+model=smalltalk.send(smalltalk.send(path,"_allButFirst",[]),"_inject_into_",[smalltalk.send(smalltalk.send(self,"_byName_",[smalltalk.send(path,"_first",[])]),"_payload",[]),(function(soFar,segment){
+return smalltalk.send(soFar,"_at_",[segment]);
+})]);
+smalltalk.send(aBlock,"_value_",[model]);
+return self}
+}),
+smalltalk.Trapped);
+
 smalltalk.addMethod(
 "_register_name_",
 smalltalk.method({
@@ -250,13 +287,12 @@ fn: function (path,aBlock){
 var self=this;
 smalltalk.send(path,"_trapDescend_",[(function(){
 var actual;
-var model;
 actual=smalltalk.send((smalltalk.Trapped || Trapped),"_path",[]);
 actual;
-model=smalltalk.send(smalltalk.send("<< ","__comma",[actual]),"__comma",[" >>"]);
-model;
 return smalltalk.send((function(){
+return smalltalk.send(smalltalk.send((smalltalk.Trapped || Trapped),"_current",[]),"_read_do_",[actual,(function(model){
 return smalltalk.send(aBlock,"_value_value_",[self,model]);
+})]);
 }),"_fork",[]);
 })]);
 return self}

+ 57 - 6
js/Trapped-Frontend.js

@@ -1,5 +1,5 @@
 smalltalk.addPackage('Trapped-Frontend', {});
-smalltalk.addClass('TrappedFly', smalltalk.Object, [], 'Trapped-Frontend');
+smalltalk.addClass('TrappedFly', smalltalk.Object, ['payload'], 'Trapped-Frontend');
 smalltalk.addMethod(
 "_name",
 smalltalk.method({
@@ -18,6 +18,38 @@ referencedClasses: []
 }),
 smalltalk.TrappedFly);
 
+smalltalk.addMethod(
+"_payload",
+smalltalk.method({
+selector: "payload",
+category: 'accessing',
+fn: function (){
+var self=this;
+return self["@payload"];
+},
+args: [],
+source: "payload\x0a\x09^payload",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.TrappedFly);
+
+smalltalk.addMethod(
+"_payload_",
+smalltalk.method({
+selector: "payload:",
+category: 'accessing',
+fn: function (anObject){
+var self=this;
+self["@payload"]=anObject;
+return self},
+args: ["anObject"],
+source: "payload: anObject\x0a\x09payload := anObject",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.TrappedFly);
+
 smalltalk.addMethod(
 "_start",
 smalltalk.method({
@@ -149,6 +181,26 @@ referencedClasses: []
 }),
 smalltalk.Trapped);
 
+smalltalk.addMethod(
+"_read_do_",
+smalltalk.method({
+selector: "read:do:",
+category: 'accessing',
+fn: function (path,aBlock){
+var self=this;
+var model;
+model=smalltalk.send(smalltalk.send(path,"_allButFirst",[]),"_inject_into_",[smalltalk.send(smalltalk.send(self,"_byName_",[smalltalk.send(path,"_first",[])]),"_payload",[]),(function(soFar,segment){
+return smalltalk.send(soFar,"_at_",[segment]);
+})]);
+smalltalk.send(aBlock,"_value_",[model]);
+return self},
+args: ["path", "aBlock"],
+source: "read: path do: aBlock\x0a\x09| model |\x0a    model := path allButFirst\x0a    \x09inject: (self byName: path first) payload\x0a        into: [ :soFar :segment | soFar at: segment ].\x0a\x09aBlock value: model.",
+messageSends: ["inject:into:", "payload", "byName:", "first", "at:", "allButFirst", "value:"],
+referencedClasses: []
+}),
+smalltalk.Trapped);
+
 smalltalk.addMethod(
 "_register_name_",
 smalltalk.method({
@@ -336,19 +388,18 @@ fn: function (path,aBlock){
 var self=this;
 smalltalk.send(path,"_trapDescend_",[(function(){
 var actual;
-var model;
 actual=smalltalk.send((smalltalk.Trapped || Trapped),"_path",[]);
 actual;
-model=smalltalk.send(smalltalk.send("<< ","__comma",[actual]),"__comma",[" >>"]);
-model;
 return smalltalk.send((function(){
+return smalltalk.send(smalltalk.send((smalltalk.Trapped || Trapped),"_current",[]),"_read_do_",[actual,(function(model){
 return smalltalk.send(aBlock,"_value_value_",[self,model]);
+})]);
 }),"_fork",[]);
 })]);
 return self},
 args: ["path", "aBlock"],
-source: "trap: path read: aBlock\x0a\x09path trapDescend: [ | actual model |\x0a    \x09actual := Trapped path.\x0a        model := '<< ', actual, ' >>'.\x0a       \x09\x22TODO register for later\x22\x0a        [aBlock value: self value: model] fork\x0a    ]",
-messageSends: ["trapDescend:", "path", ",", "fork", "value:value:"],
+source: "trap: path read: aBlock\x0a\x09path trapDescend: [ | actual |\x0a    \x09actual := Trapped path.\x0a       \x09\x22TODO register for later\x22\x0a        [ Trapped current read: actual do: [ :model |\x0a        \x09aBlock value: self value: model\x0a    \x09]] fork\x0a    ]",
+messageSends: ["trapDescend:", "path", "fork", "read:do:", "value:value:", "current"],
 referencedClasses: ["Trapped"]
 }),
 smalltalk.TagBrush);

+ 12 - 0
st/Trapped-Demo.st

@@ -3,6 +3,12 @@ TrappedFly subclass: #App
 	instanceVariableNames: ''
 	package: 'Trapped-Demo'!
 
+!App methodsFor: 'initialization'!
+
+initialize
+	self payload: #{'items'->#('hello' 'world')}
+! !
+
 Widget subclass: #AppView
 	instanceVariableNames: ''
 	package: 'Trapped-Demo'!
@@ -18,6 +24,12 @@ TrappedFly subclass: #Name
 	instanceVariableNames: ''
 	package: 'Trapped-Demo'!
 
+!Name methodsFor: 'initialization'!
+
+initialize
+	self payload: 'To-Do List'
+! !
+
 Widget subclass: #NameView
 	instanceVariableNames: ''
 	package: 'Trapped-Demo'!

+ 23 - 4
st/Trapped-Frontend.st

@@ -1,8 +1,18 @@
 Smalltalk current createPackage: 'Trapped-Frontend' properties: #{}!
 Object subclass: #TrappedFly
-	instanceVariableNames: ''
+	instanceVariableNames: 'payload'
 	package: 'Trapped-Frontend'!
 
+!TrappedFly methodsFor: 'accessing'!
+
+payload
+	^payload
+!
+
+payload: anObject
+	payload := anObject
+! !
+
 !TrappedFly methodsFor: 'action'!
 
 name
@@ -53,6 +63,14 @@ byName: aString
 	^ registry at: aString
 !
 
+read: path do: aBlock
+	| model |
+    model := path allButFirst
+    	inject: (self byName: path first) payload
+        into: [ :soFar :segment | soFar at: segment ].
+	aBlock value: model.
+!
+
 register: aFly name: aString
 	registry at: aString put: aFly
 ! !
@@ -128,11 +146,12 @@ trapDescend: aBlock
 !TagBrush methodsFor: '*Trapped-Frontend'!
 
 trap: path read: aBlock
-	path trapDescend: [ | actual model |
+	path trapDescend: [ | actual |
     	actual := Trapped path.
-        model := '<< ', actual, ' >>'.
        	"TODO register for later"
-        [aBlock value: self value: model] fork
+        [ Trapped current read: actual do: [ :model |
+        	aBlock value: self value: model
+    	]] fork
     ]
 !