Trapped-Counter.st 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 methodsFor: 'accessing'!
  40. value
  41. ^value
  42. !
  43. value: aNumber
  44. value := aNumber
  45. ! !
  46. !AppModel methodsFor: 'action'!
  47. decrement
  48. value := value - 1
  49. !
  50. increment
  51. value := value + 1
  52. ! !
  53. !AppModel methodsFor: 'initialization'!
  54. initialize
  55. super initialize.
  56. value := 0
  57. ! !