Browse Source

Use Axxord-based blackboard.

Herbert Vojčík 6 years ago
parent
commit
46eca3206f

+ 4 - 4
example-counter/counter.html

@@ -25,7 +25,7 @@
                     require(["amber-ide-starter-dialog"], function (dlg) { dlg.start(); });
 
                     $(function () {
-                        blackboard = amber.globals.App._new();
+                        blackboard = amber.globals.TrappedCounter._new();
                         amber.globals.Trapped._start_([blackboard]);
                     });
                 });
@@ -34,8 +34,8 @@
     </script>
 </head>
 <body>
-<h2 data-trap="App ~value"></h2>
-<button data-trap="App: (signal increment) whenClicked">++</button>
-<button data-trap="App: (signal decrement) whenClicked">--</button>
+<h2 data-trap="TrappedCounter ~value"></h2>
+<button data-trap="TrappedCounter: (signal increment) whenClicked">++</button>
+<button data-trap="TrappedCounter: (signal decrement) whenClicked">--</button>
 </body>
 </html>

+ 15 - 58
example-counter/src/Trapped-Counter.js

@@ -1,4 +1,4 @@
-define(["amber/boot", "amber_core/Kernel-Objects", "trapped/Trapped-Backend"], function($boot){"use strict";
+define(["amber/boot", "amber_core/Kernel-Objects"], function($boot){"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;
@@ -7,51 +7,7 @@ $core.addPackage("Trapped-Counter");
 $core.packages["Trapped-Counter"].innerEval = function (expr) { return eval(expr); };
 $core.packages["Trapped-Counter"].transport = {"type":"amd","amdNamespace":"trapped-counter"};
 
-$core.addClass("App", $globals.DirectTrapper, [], "Trapped-Counter");
-//>>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}";
-//>>excludeEnd("ide");
-$core.addMethod(
-$core.method({
-selector: "initialize",
-protocol: "initialization",
-fn: function (){
-var self=this,$self=this;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-var $1;
-(
-//>>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);
-$self._model_($recv($globals.AppModel)._new());
-return self;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.App)});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: [],
-source: "initialize\x0a\x09super initialize.\x0a    self axon: SimpleAxon new.\x0a    self model: AppModel new",
-referencedClasses: ["SimpleAxon", "AppModel"],
-//>>excludeEnd("ide");
-messageSends: ["initialize", "axon:", "new", "model:"]
-}),
-$globals.App);
-
-
-
-$core.addClass("AppModel", $globals.Object, ["value"], "Trapped-Counter");
+$core.addClass("TrappedCounter", $globals.Object, ["value"], "Trapped-Counter");
 $core.addMethod(
 $core.method({
 selector: "decrement",
@@ -64,7 +20,7 @@ return $core.withContext(function($ctx1) {
 $self["@value"]=$recv($self["@value"]).__minus((1));
 return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"decrement",{},$globals.AppModel)});
+}, function($ctx1) {$ctx1.fill(self,"decrement",{},$globals.TrappedCounter)});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
@@ -74,7 +30,7 @@ referencedClasses: [],
 //>>excludeEnd("ide");
 messageSends: ["-"]
 }),
-$globals.AppModel);
+$globals.TrappedCounter);
 
 $core.addMethod(
 $core.method({
@@ -88,7 +44,7 @@ return $core.withContext(function($ctx1) {
 $self["@value"]=$recv($self["@value"]).__plus((1));
 return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"increment",{},$globals.AppModel)});
+}, function($ctx1) {$ctx1.fill(self,"increment",{},$globals.TrappedCounter)});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
@@ -98,7 +54,7 @@ referencedClasses: [],
 //>>excludeEnd("ide");
 messageSends: ["+"]
 }),
-$globals.AppModel);
+$globals.TrappedCounter);
 
 $core.addMethod(
 $core.method({
@@ -113,24 +69,25 @@ return $core.withContext(function($ctx1) {
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.supercall = true,
 //>>excludeEnd("ctx");
-($globals.AppModel.superclass||$boot.nilAsClass).fn.prototype._initialize.apply($self, []));
+($globals.TrappedCounter.superclass||$boot.nilAsClass).fn.prototype._initialize.apply($self, []));
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.supercall = false;
 //>>excludeEnd("ctx");;
+$recv($recv($globals.SimpleAxon)._new())._registerIn_(self);
 $self["@value"]=(0);
 return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.AppModel)});
+}, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.TrappedCounter)});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "initialize\x0a\x09super initialize.\x0a\x09value := 0",
-referencedClasses: [],
+source: "initialize\x0a\x09super initialize.\x0a\x09SimpleAxon new registerIn: self.\x0a\x09value := 0",
+referencedClasses: ["SimpleAxon"],
 //>>excludeEnd("ide");
-messageSends: ["initialize"]
+messageSends: ["initialize", "registerIn:", "new"]
 }),
-$globals.AppModel);
+$globals.TrappedCounter);
 
 $core.addMethod(
 $core.method({
@@ -148,7 +105,7 @@ referencedClasses: [],
 //>>excludeEnd("ide");
 messageSends: []
 }),
-$globals.AppModel);
+$globals.TrappedCounter);
 
 $core.addMethod(
 $core.method({
@@ -167,7 +124,7 @@ referencedClasses: [],
 //>>excludeEnd("ide");
 messageSends: []
 }),
-$globals.AppModel);
+$globals.TrappedCounter);
 
 
 });

+ 5 - 44
example-counter/src/Trapped-Counter.st

@@ -1,49 +1,9 @@
 Smalltalk createPackage: 'Trapped-Counter'!
-DirectTrapper subclass: #App
-	instanceVariableNames: ''
-	package: 'Trapped-Counter'!
-!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
-! !
-
-Object subclass: #AppModel
+Object subclass: #TrappedCounter
 	instanceVariableNames: 'value'
 	package: 'Trapped-Counter'!
 
-!AppModel methodsFor: 'accessing'!
+!TrappedCounter methodsFor: 'accessing'!
 
 value
 	^value
@@ -53,7 +13,7 @@ value: aNumber
 	value := aNumber
 ! !
 
-!AppModel methodsFor: 'action'!
+!TrappedCounter methodsFor: 'action'!
 
 decrement
 	value := value - 1
@@ -63,10 +23,11 @@ increment
 	value := value + 1
 ! !
 
-!AppModel methodsFor: 'initialization'!
+!TrappedCounter methodsFor: 'initialization'!
 
 initialize
 	super initialize.
+	SimpleAxon new registerIn: self.
 	value := 0
 ! !