Trapped-Counter.st 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. Smalltalk current createPackage: 'Trapped-Counter'!
  2. ListKeyedIsolatedEntity subclass: #App
  3. instanceVariableNames: ''
  4. package: 'Trapped-Counter'!
  5. !App commentStamp!
  6. // Code from AngularJS Todo example, http://angularjs.org/#todo-js
  7. function TodoCtrl($scope) {
  8. $scope.todos = [
  9. {text:'learn angular', done:true},
  10. {text:'build an angular app', done:false}];
  11. $scope.addTodo = function() {
  12. $scope.todos.push({text:$scope.todoText, done:false});
  13. $scope.todoText = '';
  14. };
  15. $scope.remaining = function() {
  16. var count = 0;
  17. angular.forEach($scope.todos, function(todo) {
  18. count += todo.done ? 0 : 1;
  19. });
  20. return count;
  21. };
  22. $scope.archive = function() {
  23. var oldTodos = $scope.todos;
  24. $scope.todos = [];
  25. angular.forEach(oldTodos, function(todo) {
  26. if (!!todo.done) $scope.todos.push(todo);
  27. });
  28. };
  29. }!
  30. !App methodsFor: 'initialization'!
  31. initialize
  32. super initialize.
  33. self dispatcher: SimpleKeyedPubSub new.
  34. self model: AppModel new
  35. ! !
  36. Object subclass: #AppModel
  37. instanceVariableNames: 'value'
  38. package: 'Trapped-Counter'!
  39. !AppModel commentStamp!
  40. // Code from AngularJS Todo example, http://angularjs.org/#todo-js
  41. function TodoCtrl($scope) {
  42. $scope.todos = [
  43. {text:'learn angular', done:true},
  44. {text:'build an angular app', done:false}];
  45. $scope.addTodo = function() {
  46. $scope.todos.push({text:$scope.todoText, done:false});
  47. $scope.todoText = '';
  48. };
  49. $scope.remaining = function() {
  50. var count = 0;
  51. angular.forEach($scope.todos, function(todo) {
  52. count += todo.done ? 0 : 1;
  53. });
  54. return count;
  55. };
  56. $scope.archive = function() {
  57. var oldTodos = $scope.todos;
  58. $scope.todos = [];
  59. angular.forEach(oldTodos, function(todo) {
  60. if (!!todo.done) $scope.todos.push(todo);
  61. });
  62. };
  63. }!
  64. !AppModel methodsFor: 'accessing'!
  65. value
  66. ^value
  67. ! !
  68. !AppModel methodsFor: 'action'!
  69. decrement
  70. value := value - 1
  71. !
  72. increment
  73. value := value + 1
  74. ! !
  75. !AppModel methodsFor: 'initialization'!
  76. initialize
  77. super initialize.
  78. value := 0
  79. ! !