Browse Source

TrappedUnwatch exception, removing DOMless ones.

Herbert Vojčík 12 years ago
parent
commit
7a1d74a767

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

@@ -180,22 +180,36 @@ selector: "run",
 fn: function (){
 var self=this;
 var $1;
+var needsClean;
+needsClean=false;
 smalltalk.send(self,"_do_",[(function(each){
 $1=smalltalk.send(each,"_first",[]);
 if(smalltalk.assert($1)){
 return smalltalk.send((function(){
+return smalltalk.send((function(){
 return smalltalk.send(smalltalk.send(each,"_third",[]),"_value",[]);
 }),"_ensure_",[(function(){
 return smalltalk.send(each,"_at_put_",[(1),false]);
 })]);
+}),"_on_do_",[(smalltalk.TrappedUnwatch || TrappedUnwatch),(function(){
+smalltalk.send(each,"_at_put_",[(3),nil]);
+needsClean=true;
+return needsClean;
+})]);
 };
 })]);
+if(smalltalk.assert(needsClean)){
+smalltalk.send(self,"_clean",[]);
+};
 return self}
 }),
 smalltalk.TrappedDispatcher);
 
 
 
+smalltalk.addClass('TrappedUnwatch', smalltalk.Error, [], 'Trapped-Backend');
+
+
 smalltalk.addMethod(
 "_reverseTrapAt_",
 smalltalk.method({

+ 19 - 4
js/Trapped-Backend.js

@@ -181,7 +181,7 @@ smalltalk.Isolator.klass);
 
 
 smalltalk.addClass('TrappedDispatcher', smalltalk.Object, [], 'Trapped-Backend');
-smalltalk.TrappedDispatcher.comment="I am base class for change event dispatchers.\x0aI manage changed path - action block subscriptions.\x0aThese subscription must be three-element arrays\x0a\x09{ dirty. path. block }\x0a\x0aMy subclasses need to provide implementation for:\x0a\x09add:\x0a    do:\x0a    (optionally) run\x0a"
+smalltalk.TrappedDispatcher.comment="I am base class for change event dispatchers.\x0aI manage changed path - action block subscriptions.\x0aThese subscription must be three-element arrays\x0a\x09{ dirty. path. block }\x0a\x0aMy subclasses need to provide implementation for:\x0a\x09add:\x0a    do:\x0a    clean\x0a    (optionally) run\x0a"
 smalltalk.addMethod(
 "_changed_",
 smalltalk.method({
@@ -243,26 +243,41 @@ category: 'action',
 fn: function (){
 var self=this;
 var $1;
+var needsClean;
+needsClean=false;
 smalltalk.send(self,"_do_",[(function(each){
 $1=smalltalk.send(each,"_first",[]);
 if(smalltalk.assert($1)){
 return smalltalk.send((function(){
+return smalltalk.send((function(){
 return smalltalk.send(smalltalk.send(each,"_third",[]),"_value",[]);
 }),"_ensure_",[(function(){
 return smalltalk.send(each,"_at_put_",[(1),false]);
 })]);
+}),"_on_do_",[(smalltalk.TrappedUnwatch || TrappedUnwatch),(function(){
+smalltalk.send(each,"_at_put_",[(3),nil]);
+needsClean=true;
+return needsClean;
+})]);
 };
 })]);
+if(smalltalk.assert(needsClean)){
+smalltalk.send(self,"_clean",[]);
+};
 return self},
 args: [],
-source: "run\x0a\x09self do: [ :each |\x0a\x09\x09each first ifTrue: [[ each third value ] ensure: [ each at: 1 put: false ]]\x0a\x09]",
-messageSends: ["do:", "ifTrue:", "ensure:", "at:put:", "value", "third", "first"],
-referencedClasses: []
+source: "run\x0a\x09| needsClean |\x0a    needsClean := false.\x0a\x09self do: [ :each |\x0a\x09\x09each first ifTrue: [\x0a            [[ each third value ] ensure: [ each at: 1 put: false ]]\x0a            on: TrappedUnwatch do: [ each at: 3 put: nil. needsClean := true ]\x0a        ]\x0a\x09].\x0a    needsClean ifTrue: [ self clean ]",
+messageSends: ["do:", "ifTrue:", "on:do:", "at:put:", "ensure:", "value", "third", "first", "clean"],
+referencedClasses: ["TrappedUnwatch"]
 }),
 smalltalk.TrappedDispatcher);
 
 
 
+smalltalk.addClass('TrappedUnwatch', smalltalk.Error, [], 'Trapped-Backend');
+smalltalk.TrappedUnwatch.comment="SIgnal me from the watch: block to unwatch it."
+
+
 smalltalk.addMethod(
 "_reverseTrapAt_",
 smalltalk.method({

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

@@ -35,6 +35,19 @@ return self}
 }),
 smalltalk.TrappedDumbDispatcher);
 
+smalltalk.addMethod(
+"_clean",
+smalltalk.method({
+selector: "clean",
+fn: function (){
+var self=this;
+self["@queue"]=smalltalk.send(self["@queue"],"_select_",[(function(each){
+return smalltalk.send(smalltalk.send(each,"_third",[]),"_notNil",[]);
+})]);
+return self}
+}),
+smalltalk.TrappedDumbDispatcher);
+
 smalltalk.addMethod(
 "_do_",
 smalltalk.method({

+ 18 - 0
js/Trapped-Demo.js

@@ -45,6 +45,24 @@ referencedClasses: []
 }),
 smalltalk.TrappedDumbDispatcher);
 
+smalltalk.addMethod(
+"_clean",
+smalltalk.method({
+selector: "clean",
+category: 'bookkeeping',
+fn: function (){
+var self=this;
+self["@queue"]=smalltalk.send(self["@queue"],"_select_",[(function(each){
+return smalltalk.send(smalltalk.send(each,"_third",[]),"_notNil",[]);
+})]);
+return self},
+args: [],
+source: "clean\x0a\x09queue := queue select: [ :each | each third notNil ]",
+messageSends: ["select:", "notNil", "third"],
+referencedClasses: []
+}),
+smalltalk.TrappedDumbDispatcher);
+
 smalltalk.addMethod(
 "_do_",
 smalltalk.method({

+ 5 - 0
js/Trapped-Frontend.deploy.js

@@ -368,6 +368,7 @@ smalltalk.method({
 selector: "trap:read:",
 fn: function (path,aBlock){
 var self=this;
+var $1;
 smalltalk.send(path,"_trapDescend_",[(function(){
 var actual;
 var model;
@@ -376,6 +377,10 @@ actual;
 model=smalltalk.send(smalltalk.send((smalltalk.Trapped || Trapped),"_current",[]),"_byName_",[smalltalk.send(actual,"_first",[])]);
 model;
 return smalltalk.send(model,"_watch_do_",[smalltalk.send(actual,"_allButFirst",[]),(function(data){
+$1=smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(self,"_asJQuery",[]),"_closest_",["html"]),"_toArray",[]),"_isEmpty",[]);
+if(smalltalk.assert($1)){
+smalltalk.send((smalltalk.TrappedUnwatch || TrappedUnwatch),"_signal",[]);
+};
 return smalltalk.send(actual,"_trapDescend_",[(function(){
 return smalltalk.send(self,"_with_",[(function(html){
 return smalltalk.send(aBlock,"_value_value_",[data,html]);

+ 8 - 3
js/Trapped-Frontend.js

@@ -491,6 +491,7 @@ selector: "trap:read:",
 category: '*Trapped-Frontend',
 fn: function (path,aBlock){
 var self=this;
+var $1;
 smalltalk.send(path,"_trapDescend_",[(function(){
 var actual;
 var model;
@@ -499,6 +500,10 @@ actual;
 model=smalltalk.send(smalltalk.send((smalltalk.Trapped || Trapped),"_current",[]),"_byName_",[smalltalk.send(actual,"_first",[])]);
 model;
 return smalltalk.send(model,"_watch_do_",[smalltalk.send(actual,"_allButFirst",[]),(function(data){
+$1=smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(self,"_asJQuery",[]),"_closest_",["html"]),"_toArray",[]),"_isEmpty",[]);
+if(smalltalk.assert($1)){
+smalltalk.send((smalltalk.TrappedUnwatch || TrappedUnwatch),"_signal",[]);
+};
 return smalltalk.send(actual,"_trapDescend_",[(function(){
 return smalltalk.send(self,"_with_",[(function(html){
 return smalltalk.send(aBlock,"_value_value_",[data,html]);
@@ -508,9 +513,9 @@ return smalltalk.send(aBlock,"_value_value_",[data,html]);
 })]);
 return self},
 args: ["path", "aBlock"],
-source: "trap: path read: aBlock\x0a\x09path trapDescend: [ | actual model |\x0a    \x09actual := Trapped path.\x0a        model := Trapped current byName: actual first.\x0a        model watch: actual allButFirst do: [ :data |\x0a        \x09actual trapDescend: [ self with: [ :html | aBlock value: data value: html ] ]\x0a    \x09]\x0a    ]",
-messageSends: ["trapDescend:", "path", "byName:", "first", "current", "watch:do:", "allButFirst", "with:", "value:value:"],
-referencedClasses: ["Trapped"]
+source: "trap: path read: aBlock\x0a\x09path trapDescend: [ | actual model |\x0a    \x09actual := Trapped path.\x0a        model := Trapped current byName: actual first.\x0a        model watch: actual allButFirst do: [ :data |\x0a            (self asJQuery closest: 'html') toArray isEmpty ifTrue: [ TrappedUnwatch signal ].\x0a        \x09actual trapDescend: [ self with: [ :html | aBlock value: data value: html ] ]\x0a    \x09]\x0a    ]",
+messageSends: ["trapDescend:", "path", "byName:", "first", "current", "watch:do:", "allButFirst", "ifTrue:", "signal", "isEmpty", "toArray", "closest:", "asJQuery", "with:", "value:value:"],
+referencedClasses: ["Trapped", "TrappedUnwatch"]
 }),
 smalltalk.TagBrush);
 

+ 15 - 2
st/Trapped-Backend.st

@@ -85,6 +85,7 @@ These subscription must be three-element arrays
 My subclasses need to provide implementation for:
 	add:
     do:
+    clean
     (optionally) run!
 
 !TrappedDispatcher methodsFor: 'action'!
@@ -109,11 +110,23 @@ dirty: aBoolean
 !
 
 run
+	| needsClean |
+    needsClean := false.
 	self do: [ :each |
-		each first ifTrue: [[ each third value ] ensure: [ each at: 1 put: false ]]
-	]
+		each first ifTrue: [
+            [[ each third value ] ensure: [ each at: 1 put: false ]]
+            on: TrappedUnwatch do: [ each at: 3 put: nil. needsClean := true ]
+        ]
+	].
+    needsClean ifTrue: [ self clean ]
 ! !
 
+Error subclass: #TrappedUnwatch
+	instanceVariableNames: ''
+	package: 'Trapped-Backend'!
+!TrappedUnwatch commentStamp!
+SIgnal me from the watch: block to unwatch it.!
+
 !Object methodsFor: '*Trapped-Backend'!
 
 reverseTrapAt: anObject

+ 6 - 0
st/Trapped-Demo.st

@@ -24,6 +24,12 @@ add: aTriplet
     self dirty: aTriplet first
 ! !
 
+!TrappedDumbDispatcher methodsFor: 'bookkeeping'!
+
+clean
+	queue := queue select: [ :each | each third notNil ]
+! !
+
 !TrappedDumbDispatcher methodsFor: 'enumeration'!
 
 do: aBlock

+ 1 - 0
st/Trapped-Frontend.st

@@ -192,6 +192,7 @@ trap: path read: aBlock
     	actual := Trapped path.
         model := Trapped current byName: actual first.
         model watch: actual allButFirst do: [ :data |
+            (self asJQuery closest: 'html') toArray isEmpty ifTrue: [ TrappedUnwatch signal ].
         	actual trapDescend: [ self with: [ :html | aBlock value: data value: html ] ]
     	]
     ]