Herbert Vojčík преди 11 години
родител
ревизия
2979abf681
променени са 3 файла, в които са добавени 240 реда и са изтрити 0 реда
  1. 42 0
      example-counter/counter.html
  2. 102 0
      example-counter/js/Trapped-Counter.js
  3. 96 0
      example-counter/st/Trapped-Counter.st

+ 42 - 0
example-counter/counter.html

@@ -0,0 +1,42 @@
+<!doctype html>
+<html>
+<head>
+    <title>Trapped - Counter example</title>
+    <style>
+        [data-trap] {
+            display: none
+        }
+    </style>
+    <script src="../bower_components/amber/support/amber.js"></script>
+    <script type='text/javascript' src='../bower_components/amber/support/requirejs/require.min.js'></script>
+</head>
+<body>
+<script type="text/javascript">
+    var AppEntity;
+    require.config({
+        paths: {
+            'gh_herby_trapped': '../js',
+            'gh_herby_trapped_counter': 'js',
+            'gh_herby_trapped_counter/_source': 'st'
+        }
+    });
+    require(
+            ["amber/devel",
+                "gh_herby_trapped/Trapped-Processors", "gh_herby_trapped_counter/Trapped-Counter" ],
+            function (smalltalk) {
+                smalltalk.defaultAmdNamespace = 'gh_herby_trapped_todo';
+                smalltalk.initialize();
+
+                $(function () {
+                    smalltalk.Browser._openOn_(smalltalk.App);
+                    AppEntity = smalltalk.App._new();
+                    smalltalk.Trapped._start_([AppEntity]);
+                });
+            }
+    );
+</script>
+<h2 data-trap="App #value"></h2>
+<button data-trap="App: (signal increment) whenClicked">++</button>
+<button data-trap="App: (signal decrement) whenClicked">--</button>
+</body>
+</html>

+ 102 - 0
example-counter/js/Trapped-Counter.js

@@ -0,0 +1,102 @@
+define("gh_herby_trapped_counter/Trapped-Counter", ["amber_vm/smalltalk", "amber_vm/nil", "amber_vm/_st", "gh_herby_trapped/Trapped-Backend", "amber_core/Kernel-Objects"], function(smalltalk,nil,_st){
+smalltalk.addPackage('Trapped-Counter');
+smalltalk.packages["Trapped-Counter"].transport = {"type":"amd","amdNamespace":"gh_herby_trapped_counter"};
+
+smalltalk.addClass('App', smalltalk.ListKeyedIsolatedEntity, [], 'Trapped-Counter');
+smalltalk.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}";
+smalltalk.addMethod(
+smalltalk.method({
+selector: "initialize",
+category: 'initialization',
+fn: function (){
+var self=this;
+function $SimpleKeyedPubSub(){return smalltalk.SimpleKeyedPubSub||(typeof SimpleKeyedPubSub=="undefined"?nil:SimpleKeyedPubSub)}
+function $AppModel(){return smalltalk.AppModel||(typeof AppModel=="undefined"?nil:AppModel)}
+return smalltalk.withContext(function($ctx1) { 
+var $1;
+smalltalk.App.superclass.fn.prototype._initialize.apply(_st(self), []);
+$1=_st($SimpleKeyedPubSub())._new();
+$ctx1.sendIdx["new"]=1;
+self._dispatcher_($1);
+self._model_(_st($AppModel())._new());
+return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.App)})},
+args: [],
+source: "initialize\x0a\x09super initialize.\x0a    self dispatcher: SimpleKeyedPubSub new.\x0a    self model: AppModel new",
+messageSends: ["initialize", "dispatcher:", "new", "model:"],
+referencedClasses: ["SimpleKeyedPubSub", "AppModel"]
+}),
+smalltalk.App);
+
+
+
+smalltalk.addClass('AppModel', smalltalk.Object, ['value'], 'Trapped-Counter');
+smalltalk.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}";
+smalltalk.addMethod(
+smalltalk.method({
+selector: "decrement",
+category: 'action',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+self["@value"]=_st(self["@value"]).__minus((1));
+return self}, function($ctx1) {$ctx1.fill(self,"decrement",{},smalltalk.AppModel)})},
+args: [],
+source: "decrement\x0a\x09value := value - 1",
+messageSends: ["-"],
+referencedClasses: []
+}),
+smalltalk.AppModel);
+
+smalltalk.addMethod(
+smalltalk.method({
+selector: "increment",
+category: 'action',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+self["@value"]=_st(self["@value"]).__plus((1));
+return self}, function($ctx1) {$ctx1.fill(self,"increment",{},smalltalk.AppModel)})},
+args: [],
+source: "increment\x0a\x09value := value + 1",
+messageSends: ["+"],
+referencedClasses: []
+}),
+smalltalk.AppModel);
+
+smalltalk.addMethod(
+smalltalk.method({
+selector: "initialize",
+category: 'initialization',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+smalltalk.AppModel.superclass.fn.prototype._initialize.apply(_st(self), []);
+self["@value"]=(0);
+return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.AppModel)})},
+args: [],
+source: "initialize\x0a\x09super initialize.\x0a\x09value := 0",
+messageSends: ["initialize"],
+referencedClasses: []
+}),
+smalltalk.AppModel);
+
+smalltalk.addMethod(
+smalltalk.method({
+selector: "value",
+category: 'accessing',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+var $1;
+$1=self["@value"];
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"value",{},smalltalk.AppModel)})},
+args: [],
+source: "value\x0a\x09^value",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.AppModel);
+
+
+});

+ 96 - 0
example-counter/st/Trapped-Counter.st

@@ -0,0 +1,96 @@
+Smalltalk current createPackage: 'Trapped-Counter'!
+ListKeyedIsolatedEntity 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 dispatcher: SimpleKeyedPubSub new.
+    self model: AppModel new
+! !
+
+Object subclass: #AppModel
+	instanceVariableNames: 'value'
+	package: 'Trapped-Counter'!
+!AppModel 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);
+    });
+  };
+}!
+
+!AppModel methodsFor: 'accessing'!
+
+value
+	^value
+! !
+
+!AppModel methodsFor: 'action'!
+
+decrement
+	value := value - 1
+!
+
+increment
+	value := value + 1
+! !
+
+!AppModel methodsFor: 'initialization'!
+
+initialize
+	super initialize.
+	value := 0
+! !
+