Browse Source

asEavModel: in favour of asTrapPathOn:

Herbert Vojčík 12 years ago
parent
commit
1cda8bf9ae

+ 1 - 1
demo.html

@@ -6,7 +6,7 @@
 <body>
 <script type="text/javascript">
     loadAmber({
-        packages:['Trapped-Common', 'Trapped-Frontend', 'Trapped-Demo'],
+        packages:['Trapped-Common', 'Trapped-Backend', 'Trapped-Frontend', 'Trapped-Demo'],
         packageHome:'./',
         ready:function () {
             $(function() {

+ 38 - 0
js/Trapped-Backend.deploy.js

@@ -129,3 +129,41 @@ return $1;
 smalltalk.Isolator.klass);
 
 
+smalltalk.addMethod(
+"_asEavModel",
+smalltalk.method({
+selector: "asEavModel",
+fn: function (){
+var self=this;
+var $1;
+var model;
+model=smalltalk.send((smalltalk.EavModel || EavModel),"_new",[]);
+smalltalk.send(model,"_getBlock_",[(function(anObject){
+return smalltalk.send(self,"_inject_into_",[anObject,(function(soFar,segment){
+if(($receiver = soFar) == nil || $receiver == undefined){
+return soFar;
+} else {
+return smalltalk.send(segment,"_reverseTrapAt_",[soFar]);
+};
+})]);
+})]);
+$1=smalltalk.send(self,"_isEmpty",[]);
+if(! smalltalk.assert($1)){
+smalltalk.send(model,"_putBlock_",[(function(anObject,value){
+var penultimate;
+penultimate=smalltalk.send(smalltalk.send(self,"_allButLast",[]),"_inject_into_",[anObject,(function(soFar,segment){
+if(($receiver = soFar) == nil || $receiver == undefined){
+return soFar;
+} else {
+return smalltalk.send(segment,"_reverseTrapAt_",[soFar]);
+};
+})]);
+penultimate;
+return smalltalk.send(smalltalk.send(self,"_last",[]),"_reverseTrapAt_put_",[penultimate,value]);
+})]);
+};
+return model;
+}
+}),
+smalltalk.SequenceableCollection);
+

+ 43 - 0
js/Trapped-Backend.js

@@ -180,3 +180,46 @@ referencedClasses: []
 smalltalk.Isolator.klass);
 
 
+smalltalk.addMethod(
+"_asEavModel",
+smalltalk.method({
+selector: "asEavModel",
+category: '*Trapped-Backend',
+fn: function (){
+var self=this;
+var $1;
+var model;
+model=smalltalk.send((smalltalk.EavModel || EavModel),"_new",[]);
+smalltalk.send(model,"_getBlock_",[(function(anObject){
+return smalltalk.send(self,"_inject_into_",[anObject,(function(soFar,segment){
+if(($receiver = soFar) == nil || $receiver == undefined){
+return soFar;
+} else {
+return smalltalk.send(segment,"_reverseTrapAt_",[soFar]);
+};
+})]);
+})]);
+$1=smalltalk.send(self,"_isEmpty",[]);
+if(! smalltalk.assert($1)){
+smalltalk.send(model,"_putBlock_",[(function(anObject,value){
+var penultimate;
+penultimate=smalltalk.send(smalltalk.send(self,"_allButLast",[]),"_inject_into_",[anObject,(function(soFar,segment){
+if(($receiver = soFar) == nil || $receiver == undefined){
+return soFar;
+} else {
+return smalltalk.send(segment,"_reverseTrapAt_",[soFar]);
+};
+})]);
+penultimate;
+return smalltalk.send(smalltalk.send(self,"_last",[]),"_reverseTrapAt_put_",[penultimate,value]);
+})]);
+};
+return model;
+},
+args: [],
+source: "asEavModel\x0a    | model |\x0a    model := EavModel new.\x0a    model getBlock: [ :anObject |\x0a        self inject: anObject into: [ :soFar :segment |\x0a            soFar ifNotNil: [ segment reverseTrapAt: soFar ]]].\x0a    self isEmpty ifFalse: [\x0a        model putBlock: [ :anObject :value | | penultimate |\x0a            penultimate :=  self allButLast inject: anObject into: [ :soFar :segment |\x0a                soFar ifNotNil: [ segment reverseTrapAt: soFar ]].\x0a            self last reverseTrapAt: penultimate put: value ]].\x0a    ^model",
+messageSends: ["new", "getBlock:", "inject:into:", "ifNotNil:", "reverseTrapAt:", "ifFalse:", "putBlock:", "allButLast", "reverseTrapAt:put:", "last", "isEmpty"],
+referencedClasses: ["EavModel"]
+}),
+smalltalk.SequenceableCollection);
+

+ 1 - 22
js/Trapped-Common.deploy.js

@@ -144,9 +144,7 @@ var self=this;
 smalltalk.send(smalltalk.send(self,"_dispatcher",[]),"_add_",[[true,path,(function(){
 return smalltalk.send(self,"_read_do_",[path,aBlock]);
 })]]);
-smalltalk.send((function(){
-return smalltalk.send(smalltalk.send(self,"_dispatcher",[]),"_run",[]);
-}),"_fork",[]);
+smalltalk.send(smalltalk.send(self,"_dispatcher",[]),"_dirty_",[true]);
 return self}
 }),
 smalltalk.TrappedModelWrapper);
@@ -186,25 +184,6 @@ return self}
 }),
 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({

+ 3 - 29
js/Trapped-Common.js

@@ -192,13 +192,11 @@ var self=this;
 smalltalk.send(smalltalk.send(self,"_dispatcher",[]),"_add_",[[true,path,(function(){
 return smalltalk.send(self,"_read_do_",[path,aBlock]);
 })]]);
-smalltalk.send((function(){
-return smalltalk.send(smalltalk.send(self,"_dispatcher",[]),"_run",[]);
-}),"_fork",[]);
+smalltalk.send(smalltalk.send(self,"_dispatcher",[]),"_dirty_",[true]);
 return self},
 args: ["path", "aBlock"],
-source: "watch: path do: aBlock\x0a\x09self dispatcher add: { true. path. [ self read: path do: aBlock ] }.\x0a    [ self dispatcher run ] fork",
-messageSends: ["add:", "read:do:", "dispatcher", "fork", "run"],
+source: "watch: path do: aBlock\x0a\x09self dispatcher add: { true. path. [ self read: path do: aBlock ] }.\x0a    self dispatcher dirty: true",
+messageSends: ["add:", "read:do:", "dispatcher", "dirty:"],
 referencedClasses: []
 }),
 smalltalk.TrappedModelWrapper);
@@ -253,30 +251,6 @@ 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({

+ 7 - 7
js/Trapped-Demo.deploy.js

@@ -74,12 +74,12 @@ smalltalk.method({
 selector: "modify:do:",
 fn: function (path,aBlock){
 var self=this;
-var data;
 var newValue;
-data=smalltalk.send(smalltalk.send(path,"_allButLast",[]),"_asTrapPathOn_",[smalltalk.send(self,"_payload",[])]);
-newValue=smalltalk.send(aBlock,"_value_",[smalltalk.send([smalltalk.send(path,"_last",[])],"_asTrapPathOn_",[data])]);
+var eavModel;
+eavModel=smalltalk.send(path,"_asEavModel",[]);
+newValue=smalltalk.send(aBlock,"_value_",[smalltalk.send(eavModel,"_on_",[smalltalk.send(self,"_payload",[])])]);
 smalltalk.send((function(){
-return smalltalk.send(smalltalk.send(path,"_last",[]),"_reverseTrapAt_put_",[data,newValue]);
+return smalltalk.send(eavModel,"_on_put_",[smalltalk.send(self,"_payload",[]),newValue]);
 }),"_ensure_",[(function(){
 return smalltalk.send(smalltalk.send(self,"_dispatcher",[]),"_changed_",[path]);
 })]);
@@ -93,9 +93,9 @@ smalltalk.method({
 selector: "read:do:",
 fn: function (path,aBlock){
 var self=this;
-var data;
-data=smalltalk.send(path,"_asTrapPathOn_",[smalltalk.send(self,"_payload",[])]);
-smalltalk.send(aBlock,"_value_",[data]);
+var eavModel;
+eavModel=smalltalk.send(path,"_asEavModel",[]);
+smalltalk.send(aBlock,"_value_",[smalltalk.send(eavModel,"_on_",[smalltalk.send(self,"_payload",[])])]);
 return self}
 }),
 smalltalk.TrappedPlainModel);

+ 11 - 11
js/Trapped-Demo.js

@@ -100,19 +100,19 @@ selector: "modify:do:",
 category: 'action',
 fn: function (path,aBlock){
 var self=this;
-var data;
 var newValue;
-data=smalltalk.send(smalltalk.send(path,"_allButLast",[]),"_asTrapPathOn_",[smalltalk.send(self,"_payload",[])]);
-newValue=smalltalk.send(aBlock,"_value_",[smalltalk.send([smalltalk.send(path,"_last",[])],"_asTrapPathOn_",[data])]);
+var eavModel;
+eavModel=smalltalk.send(path,"_asEavModel",[]);
+newValue=smalltalk.send(aBlock,"_value_",[smalltalk.send(eavModel,"_on_",[smalltalk.send(self,"_payload",[])])]);
 smalltalk.send((function(){
-return smalltalk.send(smalltalk.send(path,"_last",[]),"_reverseTrapAt_put_",[data,newValue]);
+return smalltalk.send(eavModel,"_on_put_",[smalltalk.send(self,"_payload",[]),newValue]);
 }),"_ensure_",[(function(){
 return smalltalk.send(smalltalk.send(self,"_dispatcher",[]),"_changed_",[path]);
 })]);
 return self},
 args: ["path", "aBlock"],
-source: "modify: path do: aBlock\x0a\x09| data newValue |\x0a    data := path allButLast asTrapPathOn: self payload.\x0a\x09newValue := aBlock value: ({ path last } asTrapPathOn: data).\x0a    [ path last reverseTrapAt: data put: newValue ] ensure: [ self dispatcher changed: path ]",
-messageSends: ["asTrapPathOn:", "payload", "allButLast", "value:", "last", "ensure:", "changed:", "dispatcher", "reverseTrapAt:put:"],
+source: "modify: path do: aBlock\x0a    | newValue eavModel |\x0a    eavModel := path asEavModel.\x0a    newValue := aBlock value: (eavModel on: self payload).\x0a    [ eavModel on: self payload put: newValue ] ensure: [ self dispatcher changed: path ]\x0a",
+messageSends: ["asEavModel", "value:", "on:", "payload", "ensure:", "changed:", "dispatcher", "on:put:"],
 referencedClasses: []
 }),
 smalltalk.TrappedPlainModel);
@@ -124,13 +124,13 @@ selector: "read:do:",
 category: 'action',
 fn: function (path,aBlock){
 var self=this;
-var data;
-data=smalltalk.send(path,"_asTrapPathOn_",[smalltalk.send(self,"_payload",[])]);
-smalltalk.send(aBlock,"_value_",[data]);
+var eavModel;
+eavModel=smalltalk.send(path,"_asEavModel",[]);
+smalltalk.send(aBlock,"_value_",[smalltalk.send(eavModel,"_on_",[smalltalk.send(self,"_payload",[])])]);
 return self},
 args: ["path", "aBlock"],
-source: "read: path do: aBlock\x0a\x09| data |\x0a    data := path asTrapPathOn: self payload.\x0a\x09aBlock value: data.",
-messageSends: ["asTrapPathOn:", "payload", "value:"],
+source: "read: path do: aBlock\x0a    | eavModel |\x0a    eavModel := path asEavModel.\x0a    aBlock value: (eavModel on: self payload)\x0a",
+messageSends: ["asEavModel", "value:", "on:", "payload"],
 referencedClasses: []
 }),
 smalltalk.TrappedPlainModel);

+ 16 - 0
st/Trapped-Backend.st

@@ -73,3 +73,19 @@ on: anObject
 ^self new root: anObject
 ! !
 
+!SequenceableCollection methodsFor: '*Trapped-Backend'!
+
+asEavModel
+    | model |
+    model := EavModel new.
+    model getBlock: [ :anObject |
+        self inject: anObject into: [ :soFar :segment |
+            soFar ifNotNil: [ segment reverseTrapAt: soFar ]]].
+    self isEmpty ifFalse: [
+        model putBlock: [ :anObject :value | | penultimate |
+            penultimate :=  self allButLast inject: anObject into: [ :soFar :segment |
+                soFar ifNotNil: [ segment reverseTrapAt: soFar ]].
+            self last reverseTrapAt: penultimate put: value ]].
+    ^model
+! !
+

+ 1 - 9
st/Trapped-Common.st

@@ -86,7 +86,7 @@ start
 
 watch: path do: aBlock
 	self dispatcher add: { true. path. [ self read: path do: aBlock ] }.
-    [ self dispatcher run ] fork
+    self dispatcher dirty: true
 ! !
 
 !TrappedModelWrapper class methodsFor: 'action'!
@@ -105,14 +105,6 @@ reverseTrapAt: anObject put: value
 	self error: 'Trapped cannot put at ', self class name, ' type key.'
 ! !
 
-!SequenceableCollection methodsFor: '*Trapped-Common'!
-
-asTrapPathOn: anObject
-    ^ self inject: anObject into: [ :soFar :segment |
-        soFar ifNotNil: [ segment reverseTrapAt: soFar ]
-    ]
-! !
-
 !String methodsFor: '*Trapped-Common'!
 
 reverseTrapAt: anObject

+ 7 - 7
st/Trapped-Demo.st

@@ -41,16 +41,16 @@ TrappedModelWrapper subclass: #TrappedPlainModel
 !TrappedPlainModel methodsFor: 'action'!
 
 modify: path do: aBlock
-	| data newValue |
-    data := path allButLast asTrapPathOn: self payload.
-	newValue := aBlock value: ({ path last } asTrapPathOn: data).
-    [ path last reverseTrapAt: data put: newValue ] ensure: [ self dispatcher changed: path ]
+    | newValue eavModel |
+    eavModel := path asEavModel.
+    newValue := aBlock value: (eavModel on: self payload).
+    [ eavModel on: self payload put: newValue ] ensure: [ self dispatcher changed: path ]
 !
 
 read: path do: aBlock
-	| data |
-    data := path asTrapPathOn: self payload.
-	aBlock value: data.
+    | eavModel |
+    eavModel := path asEavModel.
+    aBlock value: (eavModel on: self payload)
 ! !
 
 !TrappedPlainModel methodsFor: 'initialization'!