Browse Source

TrappedPosition pulled up from TrappedSnapshot

Herbert Vojčík 8 years ago
parent
commit
c540bd7057
4 changed files with 211 additions and 142 deletions
  1. 135 0
      src/Trapped-Backend.js
  2. 33 0
      src/Trapped-Backend.st
  3. 31 114
      src/Trapped-Frontend.js
  4. 12 28
      src/Trapped-Frontend.st

+ 135 - 0
src/Trapped-Backend.js

@@ -374,6 +374,141 @@ messageSends: ["root:", "new"]
 $globals.Isolator.klass);
 
 
+$core.addClass('TrappedPosition', $globals.Object, ['path', 'model'], 'Trapped-Backend');
+$core.addMethod(
+$core.method({
+selector: "model",
+protocol: 'accessing',
+fn: function (){
+var self=this;
+var $1;
+$1=self["@model"];
+return $1;
+
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "model\x0a\x09^model",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: []
+}),
+$globals.TrappedPosition);
+
+$core.addMethod(
+$core.method({
+selector: "modify:",
+protocol: 'action',
+fn: function (aBlock){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+$recv(self._model())._modify_do_(self._path(),aBlock);
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"modify:",{aBlock:aBlock},$globals.TrappedPosition)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["aBlock"],
+source: "modify: aBlock\x0a\x09self model modify: self path do: aBlock",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["modify:do:", "model", "path"]
+}),
+$globals.TrappedPosition);
+
+$core.addMethod(
+$core.method({
+selector: "path",
+protocol: 'accessing',
+fn: function (){
+var self=this;
+var $1;
+$1=self["@path"];
+return $1;
+
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "path\x0a\x09^path",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: []
+}),
+$globals.TrappedPosition);
+
+$core.addMethod(
+$core.method({
+selector: "path:model:",
+protocol: 'accessing',
+fn: function (anArray,aTrappedMW){
+var self=this;
+self["@path"]=anArray;
+self["@model"]=aTrappedMW;
+return self;
+
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["anArray", "aTrappedMW"],
+source: "path: anArray model: aTrappedMW\x0a\x09path := anArray.\x0a    model := aTrappedMW",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: []
+}),
+$globals.TrappedPosition);
+
+$core.addMethod(
+$core.method({
+selector: "read:",
+protocol: 'action',
+fn: function (aBlock){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+$recv(self._model())._read_do_(self._path(),aBlock);
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"read:",{aBlock:aBlock},$globals.TrappedPosition)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["aBlock"],
+source: "read: aBlock\x0a\x09self model read: self path do: aBlock",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["read:do:", "model", "path"]
+}),
+$globals.TrappedPosition);
+
+$core.addMethod(
+$core.method({
+selector: "watch:",
+protocol: 'action',
+fn: function (aBlock){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+$recv(self._model())._watch_do_(self._path(),aBlock);
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"watch:",{aBlock:aBlock},$globals.TrappedPosition)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["aBlock"],
+source: "watch: aBlock\x0a\x09self model watch: self path do: aBlock",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["watch:do:", "model", "path"]
+}),
+$globals.TrappedPosition);
+
+
+
 $core.addClass('Trapper', $globals.AxonizedObject, ['payload'], 'Trapped-Backend');
 //>>excludeStart("ide", pragmas.excludeIdeData);
 $globals.Trapper.comment="A portmanteau of 'Trapped wrapper', I am base class for model objects wrapped by Trapped.\x0a\x0aWrapped object is indexed by #('string-at-index' #selector numeric-at-index) array paths. Operations using this indexing are:\x0a\x0a - `read:do` to get the indexed content\x0a - `modify:do:` to get and modify the indexed content, and\x0a - `watch:do:` to subscribe to changes of the indexed content.\x0a\x0aThe wrapped model can be any smalltalk object.\x0a\x0aMy subclasses need to provide implementation for:\x0a\x0a - read:do:\x0a - modify:do:\x0a\x0aand must issue these calls when initializing:\x0a\x0a - axon: (with a subclass of `AxonBase`)\x0a - model: (with a wrapped object, after `axon:`)";

+ 33 - 0
src/Trapped-Backend.st

@@ -96,6 +96,39 @@ on: anObject
 ^self new root: anObject
 ! !
 
+Object subclass: #TrappedPosition
+	instanceVariableNames: 'path model'
+	package: 'Trapped-Backend'!
+
+!TrappedPosition methodsFor: 'accessing'!
+
+model
+	^model
+!
+
+path
+	^path
+!
+
+path: anArray model: aTrappedMW
+	path := anArray.
+    model := aTrappedMW
+! !
+
+!TrappedPosition methodsFor: 'action'!
+
+modify: aBlock
+	self model modify: self path do: aBlock
+!
+
+read: aBlock
+	self model read: self path do: aBlock
+!
+
+watch: aBlock
+	self model watch: self path do: aBlock
+! !
+
 AxonizedObject subclass: #Trapper
 	instanceVariableNames: 'payload'
 	package: 'Trapped-Backend'!

+ 31 - 114
src/Trapped-Frontend.js

@@ -2,7 +2,7 @@ define("trapped/Trapped-Frontend", ["amber/boot"
 //>>excludeStart("imports", pragmas.excludeImports);
 , "amber/jquery/Wrappers-JQuery", "amber/web/Web"
 //>>excludeEnd("imports");
-, "amber_core/Kernel-Objects", "amber_core/Kernel-Collections", "amber/web/Web"], function($boot
+, "amber_core/Kernel-Objects", "trapped/Trapped-Backend", "amber_core/Kernel-Collections", "amber/web/Web"], function($boot
 //>>excludeStart("imports", pragmas.excludeImports);
 
 //>>excludeEnd("imports");
@@ -1009,19 +1009,29 @@ function $TrappedSnapshot(){return $globals.TrappedSnapshot||(typeof TrappedSnap
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
+var $1,$2,$3;
 tpsc=$recv($TrappedPathStack())._current();
 $recv(tpsc)._append_do_(anArray,(function(){
-var path,model;
+var prefix,modelPath,model;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx2) {
 //>>excludeEnd("ctx");
-path=$recv($recv(tpsc)._elements())._copy();
-path;
-model=self._byName_($recv(path)._first());
+$1=$recv(tpsc)._elements();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx2.sendIdx["elements"]=1;
+//>>excludeEnd("ctx");
+prefix=$recv($1)._first();
+prefix;
+modelPath=$recv($recv(tpsc)._elements())._allButFirst();
+modelPath;
+model=self._byName_(prefix);
 model;
-return $recv(aBlock)._value_($recv($recv($TrappedSnapshot())._new())._path_model_(path,model));
+$2=$recv($TrappedSnapshot())._new();
+$recv($2)._prefix_(prefix);
+$3=$recv($2)._path_model_(modelPath,model);
+return $recv(aBlock)._value_($3);
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx2) {$ctx2.fillBlock({path:path,model:model},$ctx1,1)});
+}, function($ctx2) {$ctx2.fillBlock({prefix:prefix,modelPath:modelPath,model:model},$ctx1,1)});
 //>>excludeEnd("ctx");
 }));
 return self;
@@ -1031,10 +1041,10 @@ return self;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["anArray", "aBlock"],
-source: "descend: anArray snapshotDo: aBlock\x0a\x09| tpsc |\x0a    tpsc := TrappedPathStack current.\x0a    tpsc append: anArray do: [\x0a        | path model |\x0a        path := tpsc elements copy.\x0a   \x09    model := self byName: path first.\x0a        aBlock value: (TrappedSnapshot new path: path model: model)\x0a    ]",
+source: "descend: anArray snapshotDo: aBlock\x0a\x09| tpsc |\x0a    tpsc := TrappedPathStack current.\x0a    tpsc append: anArray do: [\x0a        | prefix modelPath model |\x0a\x09\x09prefix := tpsc elements first.\x0a\x09\x09modelPath := tpsc elements allButFirst.\x0a   \x09    model := self byName: prefix.\x0a        aBlock value: (TrappedSnapshot new prefix: prefix; path: modelPath model: model)\x0a    ]",
 referencedClasses: ["TrappedPathStack", "TrappedSnapshot"],
 //>>excludeEnd("ide");
-messageSends: ["current", "append:do:", "copy", "elements", "byName:", "first", "value:", "path:model:", "new"]
+messageSends: ["current", "append:do:", "first", "elements", "allButFirst", "byName:", "value:", "prefix:", "new", "path:model:"]
 }),
 $globals.Trapped);
 
@@ -1533,7 +1543,7 @@ $globals.TrappedPathStack);
 
 
 
-$core.addClass('TrappedSnapshot', $globals.Object, ['path', 'model'], 'Trapped-Frontend');
+$core.addClass('TrappedSnapshot', $globals.TrappedPosition, ['prefix'], 'Trapped-Frontend');
 $core.addMethod(
 $core.method({
 selector: "do:",
@@ -1544,7 +1554,7 @@ function $TrappedPathStack(){return $globals.TrappedPathStack||(typeof TrappedPa
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-$recv($recv($TrappedPathStack())._current())._with_do_(self["@path"],(function(){
+$recv($recv($TrappedPathStack())._current())._with_do_($recv([self["@prefix"]]).__comma(self["@path"]),(function(){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx2) {
 //>>excludeEnd("ctx");
@@ -1560,71 +1570,27 @@ return self;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["aBlock"],
-source: "do: aBlock\x0a\x09TrappedPathStack current with: path do: [ aBlock value: model ]",
+source: "do: aBlock\x0a\x09TrappedPathStack current with: {prefix}, path do: [ aBlock value: model ]",
 referencedClasses: ["TrappedPathStack"],
 //>>excludeEnd("ide");
-messageSends: ["with:do:", "current", "value:"]
-}),
-$globals.TrappedSnapshot);
-
-$core.addMethod(
-$core.method({
-selector: "model",
-protocol: 'accessing',
-fn: function (){
-var self=this;
-var $1;
-$1=self["@model"];
-return $1;
-
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: [],
-source: "model\x0a\x09^model",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: []
-}),
-$globals.TrappedSnapshot);
-
-$core.addMethod(
-$core.method({
-selector: "modify:",
-protocol: 'action',
-fn: function (aBlock){
-var self=this;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-$recv(self._model())._modify_do_($recv(self._path())._allButFirst(),aBlock);
-return self;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"modify:",{aBlock:aBlock},$globals.TrappedSnapshot)});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: ["aBlock"],
-source: "modify: aBlock\x0a\x09self model modify: self path allButFirst do: aBlock",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: ["modify:do:", "model", "allButFirst", "path"]
+messageSends: ["with:do:", "current", ",", "value:"]
 }),
 $globals.TrappedSnapshot);
 
 $core.addMethod(
 $core.method({
-selector: "path",
+selector: "prefix",
 protocol: 'accessing',
 fn: function (){
 var self=this;
 var $1;
-$1=self["@path"];
+$1=self["@prefix"];
 return $1;
 
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "path\x0a\x09^path",
+source: "prefix\x0a\x09^ prefix",
 referencedClasses: [],
 //>>excludeEnd("ide");
 messageSends: []
@@ -1633,72 +1599,23 @@ $globals.TrappedSnapshot);
 
 $core.addMethod(
 $core.method({
-selector: "path:model:",
+selector: "prefix:",
 protocol: 'accessing',
-fn: function (anArray,aTrappedMW){
+fn: function (anObject){
 var self=this;
-self["@path"]=anArray;
-self["@model"]=aTrappedMW;
+self["@prefix"]=anObject;
 return self;
 
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
-args: ["anArray", "aTrappedMW"],
-source: "path: anArray model: aTrappedMW\x0a\x09path := anArray.\x0a    model := aTrappedMW",
+args: ["anObject"],
+source: "prefix: anObject\x0a\x09prefix := anObject",
 referencedClasses: [],
 //>>excludeEnd("ide");
 messageSends: []
 }),
 $globals.TrappedSnapshot);
 
-$core.addMethod(
-$core.method({
-selector: "read:",
-protocol: 'action',
-fn: function (aBlock){
-var self=this;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-$recv(self._model())._read_do_($recv(self._path())._allButFirst(),aBlock);
-return self;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"read:",{aBlock:aBlock},$globals.TrappedSnapshot)});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: ["aBlock"],
-source: "read: aBlock\x0a\x09self model read: self path allButFirst do: aBlock",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: ["read:do:", "model", "allButFirst", "path"]
-}),
-$globals.TrappedSnapshot);
-
-$core.addMethod(
-$core.method({
-selector: "watch:",
-protocol: 'action',
-fn: function (aBlock){
-var self=this;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-$recv(self._model())._watch_do_($recv(self._path())._allButFirst(),aBlock);
-return self;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"watch:",{aBlock:aBlock},$globals.TrappedSnapshot)});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: ["aBlock"],
-source: "watch: aBlock\x0a\x09self model watch: self path allButFirst do: aBlock",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: ["watch:do:", "model", "allButFirst", "path"]
-}),
-$globals.TrappedSnapshot);
-
 
 $core.addMethod(
 $core.method({

+ 12 - 28
src/Trapped-Frontend.st

@@ -325,10 +325,11 @@ descend: anArray snapshotDo: aBlock
 	| tpsc |
     tpsc := TrappedPathStack current.
     tpsc append: anArray do: [
-        | path model |
-        path := tpsc elements copy.
-   	    model := self byName: path first.
-        aBlock value: (TrappedSnapshot new path: path model: model)
+        | prefix modelPath model |
+		prefix := tpsc elements first.
+		modelPath := tpsc elements allButFirst.
+   	    model := self byName: prefix.
+        aBlock value: (TrappedSnapshot new prefix: prefix; path: modelPath model: model)
     ]
 !
 
@@ -412,41 +413,24 @@ initialize
 	elements := #().
 ! !
 
-Object subclass: #TrappedSnapshot
-	instanceVariableNames: 'path model'
+TrappedPosition subclass: #TrappedSnapshot
+	instanceVariableNames: 'prefix'
 	package: 'Trapped-Frontend'!
 
 !TrappedSnapshot methodsFor: 'accessing'!
 
-model
-	^model
-!
-
-path
-	^path
+prefix
+	^ prefix
 !
 
-path: anArray model: aTrappedMW
-	path := anArray.
-    model := aTrappedMW
+prefix: anObject
+	prefix := anObject
 ! !
 
 !TrappedSnapshot methodsFor: 'action'!
 
 do: aBlock
-	TrappedPathStack current with: path do: [ aBlock value: model ]
-!
-
-modify: aBlock
-	self model modify: self path allButFirst do: aBlock
-!
-
-read: aBlock
-	self model read: self path allButFirst do: aBlock
-!
-
-watch: aBlock
-	self model watch: self path allButFirst do: aBlock
+	TrappedPathStack current with: {prefix}, path do: [ aBlock value: model ]
 ! !
 
 !Array methodsFor: '*Trapped-Frontend'!