Browse Source

Use Axxord-based blackboard.

(without isolation, it is not there yet)
Herbert Vojčík 6 years ago
parent
commit
fe1480e9b1
3 changed files with 113 additions and 136 deletions
  1. 82 82
      example-todo/src/Trapped-Todo.js
  2. 29 52
      example-todo/src/Trapped-Todo.st
  3. 2 2
      example-todo/todo.html

+ 82 - 82
example-todo/src/Trapped-Todo.js

@@ -1,134 +1,134 @@
-define(["amber/boot", "amber_core/Kernel-Objects", "trapped/Trapped-Backend", "trapped/Trapped-Frontend"], function($boot){"use strict";
+define(["amber/boot"
+//>>excludeStart("imports", pragmas.excludeImports);
+, "trapped/Trapped-Processors"
+//>>excludeEnd("imports");
+, "amber_core/Kernel-Objects", "trapped/Trapped-Frontend"], function($boot
+//>>excludeStart("imports", pragmas.excludeImports);
+
+//>>excludeEnd("imports");
+){"use strict";
 if(!$boot.nilAsReceiver)$boot.nilAsReceiver=$boot.nil;
 if(!("nilAsValue" in $boot))$boot.nilAsValue=$boot.nilAsReceiver;
 var $core=$boot.api,nil=$boot.nilAsValue,$nil=$boot.nilAsReceiver,$recv=$boot.asReceiver,$globals=$boot.globals;
 if(!$boot.nilAsClass)$boot.nilAsClass=$boot.dnu;
 $core.addPackage("Trapped-Todo");
 $core.packages["Trapped-Todo"].innerEval = function (expr) { return eval(expr); };
+$core.packages["Trapped-Todo"].imports = ["trapped/Trapped-Processors"];
 $core.packages["Trapped-Todo"].transport = {"type":"amd","amdNamespace":"trapped-todo"};
 
-$core.addClass("App", $globals.IsolatingTrapper, [], "Trapped-Todo");
+$core.addClass("TrappedTodo", $globals.Object, ["title", "todos", "todoText"], "Trapped-Todo");
 //>>excludeStart("ide", pragmas.excludeIdeData);
-$globals.App.comment="// Code from AngularJS Todo example, http://angularjs.org/#todo-js\x0afunction TodoCtrl($scope) {\x0a  $scope.todos = [\x0a    {text:'learn angular', done:true},\x0a    {text:'build an angular app', done:false}];\x0a \x0a  $scope.addTodo = function() {\x0a    $scope.todos.push({text:$scope.todoText, done:false});\x0a    $scope.todoText = '';\x0a  };\x0a \x0a  $scope.remaining = function() {\x0a    var count = 0;\x0a    angular.forEach($scope.todos, function(todo) {\x0a      count += todo.done ? 0 : 1;\x0a    });\x0a    return count;\x0a  };\x0a \x0a  $scope.archive = function() {\x0a    var oldTodos = $scope.todos;\x0a    $scope.todos = [];\x0a    angular.forEach(oldTodos, function(todo) {\x0a      if (!todo.done) $scope.todos.push(todo);\x0a    });\x0a  };\x0a}";
+$globals.TrappedTodo.comment="// Code from AngularJS Todo example, http://angularjs.org/#todo-js\x0afunction TodoCtrl($scope) {\x0a  $scope.todos = [\x0a    {text:'learn angular', done:true},\x0a    {text:'build an angular app', done:false}];\x0a \x0a  $scope.addTodo = function() {\x0a    $scope.todos.push({text:$scope.todoText, done:false});\x0a    $scope.todoText = '';\x0a  };\x0a \x0a  $scope.remaining = function() {\x0a    var count = 0;\x0a    angular.forEach($scope.todos, function(todo) {\x0a      count += todo.done ? 0 : 1;\x0a    });\x0a    return count;\x0a  };\x0a \x0a  $scope.archive = function() {\x0a    var oldTodos = $scope.todos;\x0a    $scope.todos = [];\x0a    angular.forEach(oldTodos, function(todo) {\x0a      if (!todo.done) $scope.todos.push(todo);\x0a    });\x0a  };\x0a}";
 //>>excludeEnd("ide");
 $core.addMethod(
 $core.method({
-selector: "initialize",
-protocol: "initialization",
+selector: "addTodo",
+protocol: "action",
 fn: function (){
 var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $1,$3,$2;
-(
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.supercall = true,
-//>>excludeEnd("ctx");
-($globals.App.superclass||$boot.nilAsClass).fn.prototype._initialize.apply($self, []));
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.supercall = false;
-//>>excludeEnd("ctx");;
-$1=$recv($globals.SimpleAxon)._new();
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["new"]=1;
-//>>excludeEnd("ctx");
-$self._axon_($1);
-$3=$recv($globals.AppModel)._new();
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["new"]=2;
-//>>excludeEnd("ctx");
-$2=$recv($3)._title_("Todo");
-$self._model_($2);
-$recv($self._axon())._addInterest_($recv($recv($globals.InterestedInTrapPathSubtree)._new())._aspect_block_([["todos"]],(function(){
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx2) {
-//>>excludeEnd("ctx");
-return $self._changed_([["remaining"]]);
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
-//>>excludeEnd("ctx");
-})));
-$recv((function(){
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx2) {
-//>>excludeEnd("ctx");
-return $self._modify_do_([["todos"]],(function(){
-return [$globals.HashedCollection._newFromPairs_(["text","learn trapped","done",true]),$globals.HashedCollection._newFromPairs_(["text","build a trapped app","done",false])];
-
-}));
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
-//>>excludeEnd("ctx");
-}))._valueWithTimeout_((2000));
+$recv($self._todos())._add_($globals.HashedCollection._newFromPairs_(["text",$self._todoText(),"done",false]));
+$self._todoText_("");
 return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.App)});
+}, function($ctx1) {$ctx1.fill(self,"addTodo",{},$globals.TrappedTodo)});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "initialize\x0a\x09super initialize.\x0a    self axon: SimpleAxon new.\x0a    self model: (AppModel new title: 'Todo').\x0a\x09self axon addInterest: (\x0a\x09\x09InterestedInTrapPathSubtree new\x0a\x09\x09\x09aspect: #((todos))\x0a\x09\x09\x09block: [ self changed: #((remaining)) ]).\x0a    [ self modify: #((todos)) do: [{\x0a        #{'text'->'learn trapped'. 'done'->true}.\x0a        #{'text'->'build a trapped app'. 'done'->false}\x0a    }]] valueWithTimeout: 2000",
-referencedClasses: ["SimpleAxon", "AppModel", "InterestedInTrapPathSubtree"],
+source: "addTodo\x0a    self todos add: #{'text'->self todoText. 'done'->false}.\x0a    self todoText: ''",
+referencedClasses: [],
 //>>excludeEnd("ide");
-messageSends: ["initialize", "axon:", "new", "model:", "title:", "addInterest:", "axon", "aspect:block:", "changed:", "valueWithTimeout:", "modify:do:"]
+messageSends: ["add:", "todos", "todoText", "todoText:"]
 }),
-$globals.App);
+$globals.TrappedTodo);
 
-
-
-$core.addClass("AppModel", $globals.Object, ["title", "todos", "todoText"], "Trapped-Todo");
-//>>excludeStart("ide", pragmas.excludeIdeData);
-$globals.AppModel.comment="// Code from AngularJS Todo example, http://angularjs.org/#todo-js\x0afunction TodoCtrl($scope) {\x0a  $scope.todos = [\x0a    {text:'learn angular', done:true},\x0a    {text:'build an angular app', done:false}];\x0a \x0a  $scope.addTodo = function() {\x0a    $scope.todos.push({text:$scope.todoText, done:false});\x0a    $scope.todoText = '';\x0a  };\x0a \x0a  $scope.remaining = function() {\x0a    var count = 0;\x0a    angular.forEach($scope.todos, function(todo) {\x0a      count += todo.done ? 0 : 1;\x0a    });\x0a    return count;\x0a  };\x0a \x0a  $scope.archive = function() {\x0a    var oldTodos = $scope.todos;\x0a    $scope.todos = [];\x0a    angular.forEach(oldTodos, function(todo) {\x0a      if (!todo.done) $scope.todos.push(todo);\x0a    });\x0a  };\x0a}";
-//>>excludeEnd("ide");
 $core.addMethod(
 $core.method({
-selector: "addTodo",
+selector: "archive",
 protocol: "action",
 fn: function (){
 var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-$recv($self._todos())._add_($globals.HashedCollection._newFromPairs_(["text",$self._todoText(),"done",false]));
-$self._todoText_("");
+$self._todos_($self._todosNotDone());
 return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"addTodo",{},$globals.AppModel)});
+}, function($ctx1) {$ctx1.fill(self,"archive",{},$globals.TrappedTodo)});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "addTodo\x0a    self todos add: #{'text'->self todoText. 'done'->false}.\x0a    self todoText: ''",
+source: "archive\x0a    self todos: self todosNotDone",
 referencedClasses: [],
 //>>excludeEnd("ide");
-messageSends: ["add:", "todos", "todoText", "todoText:"]
+messageSends: ["todos:", "todosNotDone"]
 }),
-$globals.AppModel);
+$globals.TrappedTodo);
 
 $core.addMethod(
 $core.method({
-selector: "archive",
-protocol: "action",
+selector: "initialize",
+protocol: "initialization",
 fn: function (){
 var self=this,$self=this;
+var axon;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-$self._todos_($self._todosNotDone());
+(
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.supercall = true,
+//>>excludeEnd("ctx");
+($globals.TrappedTodo.superclass||$boot.nilAsClass).fn.prototype._initialize.apply($self, []));
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.supercall = false;
+//>>excludeEnd("ctx");;
+axon=$recv($globals.SimpleAxon)._new();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["new"]=1;
+//>>excludeEnd("ctx");
+$recv(axon)._registerIn_(self);
+$recv(axon)._addInterest_($recv($recv($globals.InterestedInTrapPathSubtree)._new())._aspect_block_([["todos"]],(function(){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+return $recv(axon)._changed_([["remaining"]]);
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
+//>>excludeEnd("ctx");
+})));
+$recv((function(){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+return $self._axes_transform_([["todos"]],(function(){
+return [$globals.HashedCollection._newFromPairs_(["text","learn trapped","done",true]),$globals.HashedCollection._newFromPairs_(["text","build a trapped app","done",false])];
+
+}));
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
+//>>excludeEnd("ctx");
+}))._valueWithTimeout_((2000));
+$self["@title"]="Todo";
+$self["@todoText"]=nil;
+$self["@todos"]=nil;
 return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"archive",{},$globals.AppModel)});
+}, function($ctx1) {$ctx1.fill(self,"initialize",{axon:axon},$globals.TrappedTodo)});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "archive\x0a    self todos: self todosNotDone",
-referencedClasses: [],
+source: "initialize\x0a\x09| axon |\x0a\x09super initialize.\x0a\x0a    axon := SimpleAxon new.\x0a\x09axon registerIn: self.\x0a\x09\x0a\x09axon addInterest: (\x0a\x09\x09InterestedInTrapPathSubtree new\x0a\x09\x09\x09aspect: #((todos))\x0a\x09\x09\x09block: [ axon changed: #((remaining)) ]).\x0a\x0a    [ self axes: #((todos)) transform: [{\x0a        #{'text'->'learn trapped'. 'done'->true}.\x0a        #{'text'->'build a trapped app'. 'done'->false}\x0a    }]] valueWithTimeout: 2000.\x0a\x0a\x09title := 'Todo'.\x0a\x09todoText := nil.\x0a\x09todos := nil",
+referencedClasses: ["SimpleAxon", "InterestedInTrapPathSubtree"],
 //>>excludeEnd("ide");
-messageSends: ["todos:", "todosNotDone"]
+messageSends: ["initialize", "new", "registerIn:", "addInterest:", "aspect:block:", "changed:", "valueWithTimeout:", "axes:transform:"]
 }),
-$globals.AppModel);
+$globals.TrappedTodo);
 
 $core.addMethod(
 $core.method({
@@ -141,7 +141,7 @@ return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
 return $recv($self._todosNotDone())._size();
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"remaining",{},$globals.AppModel)});
+}, function($ctx1) {$ctx1.fill(self,"remaining",{},$globals.TrappedTodo)});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
@@ -151,7 +151,7 @@ referencedClasses: [],
 //>>excludeEnd("ide");
 messageSends: ["size", "todosNotDone"]
 }),
-$globals.AppModel);
+$globals.TrappedTodo);
 
 $core.addMethod(
 $core.method({
@@ -169,7 +169,7 @@ referencedClasses: [],
 //>>excludeEnd("ide");
 messageSends: []
 }),
-$globals.AppModel);
+$globals.TrappedTodo);
 
 $core.addMethod(
 $core.method({
@@ -188,7 +188,7 @@ referencedClasses: [],
 //>>excludeEnd("ide");
 messageSends: []
 }),
-$globals.AppModel);
+$globals.TrappedTodo);
 
 $core.addMethod(
 $core.method({
@@ -206,7 +206,7 @@ referencedClasses: [],
 //>>excludeEnd("ide");
 messageSends: []
 }),
-$globals.AppModel);
+$globals.TrappedTodo);
 
 $core.addMethod(
 $core.method({
@@ -225,7 +225,7 @@ referencedClasses: [],
 //>>excludeEnd("ide");
 messageSends: []
 }),
-$globals.AppModel);
+$globals.TrappedTodo);
 
 $core.addMethod(
 $core.method({
@@ -243,7 +243,7 @@ referencedClasses: [],
 //>>excludeEnd("ide");
 messageSends: []
 }),
-$globals.AppModel);
+$globals.TrappedTodo);
 
 $core.addMethod(
 $core.method({
@@ -262,7 +262,7 @@ referencedClasses: [],
 //>>excludeEnd("ide");
 messageSends: []
 }),
-$globals.AppModel);
+$globals.TrappedTodo);
 
 $core.addMethod(
 $core.method({
@@ -283,7 +283,7 @@ return $recv(each)._at_("done");
 //>>excludeEnd("ctx");
 }));
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"todosNotDone",{},$globals.AppModel)});
+}, function($ctx1) {$ctx1.fill(self,"todosNotDone",{},$globals.TrappedTodo)});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
@@ -293,7 +293,7 @@ referencedClasses: [],
 //>>excludeEnd("ide");
 messageSends: ["reject:", "todos", "at:"]
 }),
-$globals.AppModel);
+$globals.TrappedTodo);
 
 
 $core.addMethod(

+ 29 - 52
example-todo/src/Trapped-Todo.st

@@ -1,56 +1,9 @@
 Smalltalk createPackage: 'Trapped-Todo'!
-IsolatingTrapper subclass: #App
-	instanceVariableNames: ''
-	package: 'Trapped-Todo'!
-!App commentStamp!
-// Code from AngularJS Todo example, http://angularjs.org/#todo-js
-function TodoCtrl($scope) {
-  $scope.todos = [
-    {text:'learn angular', done:true},
-    {text:'build an angular app', done:false}];
- 
-  $scope.addTodo = function() {
-    $scope.todos.push({text:$scope.todoText, done:false});
-    $scope.todoText = '';
-  };
- 
-  $scope.remaining = function() {
-    var count = 0;
-    angular.forEach($scope.todos, function(todo) {
-      count += todo.done ? 0 : 1;
-    });
-    return count;
-  };
- 
-  $scope.archive = function() {
-    var oldTodos = $scope.todos;
-    $scope.todos = [];
-    angular.forEach(oldTodos, function(todo) {
-      if (!!todo.done) $scope.todos.push(todo);
-    });
-  };
-}!
-
-!App methodsFor: 'initialization'!
-
-initialize
-	super initialize.
-    self axon: SimpleAxon new.
-    self model: (AppModel new title: 'Todo').
-	self axon addInterest: (
-		InterestedInTrapPathSubtree new
-			aspect: #((todos))
-			block: [ self changed: #((remaining)) ]).
-    [ self modify: #((todos)) do: [{
-        #{'text'->'learn trapped'. 'done'->true}.
-        #{'text'->'build a trapped app'. 'done'->false}
-    }]] valueWithTimeout: 2000
-! !
-
-Object subclass: #AppModel
+(Smalltalk packageAt: 'Trapped-Todo') imports: {'trapped/Trapped-Processors'}!
+Object subclass: #TrappedTodo
 	instanceVariableNames: 'title todos todoText'
 	package: 'Trapped-Todo'!
-!AppModel commentStamp!
+!TrappedTodo commentStamp!
 // Code from AngularJS Todo example, http://angularjs.org/#todo-js
 function TodoCtrl($scope) {
   $scope.todos = [
@@ -79,7 +32,7 @@ function TodoCtrl($scope) {
   };
 }!
 
-!AppModel methodsFor: 'accessing'!
+!TrappedTodo methodsFor: 'accessing'!
 
 remaining
     ^self todosNotDone size
@@ -113,7 +66,7 @@ todosNotDone
     ^self todos reject: [ :each | each at: 'done' ]
 ! !
 
-!AppModel methodsFor: 'action'!
+!TrappedTodo methodsFor: 'action'!
 
 addTodo
     self todos add: #{'text'->self todoText. 'done'->false}.
@@ -124,6 +77,30 @@ archive
     self todos: self todosNotDone
 ! !
 
+!TrappedTodo methodsFor: 'initialization'!
+
+initialize
+	| axon |
+	super initialize.
+
+    axon := SimpleAxon new.
+	axon registerIn: self.
+	
+	axon addInterest: (
+		InterestedInTrapPathSubtree new
+			aspect: #((todos))
+			block: [ axon changed: #((remaining)) ]).
+
+    [ self axes: #((todos)) transform: [{
+        #{'text'->'learn trapped'. 'done'->true}.
+        #{'text'->'build a trapped app'. 'done'->false}
+    }]] valueWithTimeout: 2000.
+
+	title := 'Todo'.
+	todoText := nil.
+	todos := nil
+! !
+
 !TrappedProcessor class methodsFor: '*Trapped-Todo'!
 
 classDoneXxx

+ 2 - 2
example-todo/todo.html

@@ -1,5 +1,5 @@
 <!doctype html>
-<html data-trap="App: path">
+<html data-trap="TrappedTodo: path">
 <head>
     <title data-trap="~title"></title>
     <style>
@@ -23,7 +23,7 @@
                     require(["amber-ide-starter-dialog"], function (dlg) { dlg.start(); });
 
                     $(function () {
-                        blackboard = amber.globals.App._new();
+                        blackboard = amber.globals.TrappedTodo._new();
                         amber.globals.Trapped._start_([blackboard]);
                     });
                 });