Trapped-Todo.st 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. Smalltalk createPackage: 'Trapped-Todo'!
  2. (Smalltalk packageAt: 'Trapped-Todo') imports: {'trapped/Trapped-Processors'}!
  3. Object subclass: #TrappedTodo
  4. instanceVariableNames: 'title todos todoText'
  5. package: 'Trapped-Todo'!
  6. !TrappedTodo commentStamp!
  7. // Code from AngularJS Todo example, http://angularjs.org/#todo-js
  8. function TodoCtrl($scope) {
  9. $scope.todos = [
  10. {text:'learn angular', done:true},
  11. {text:'build an angular app', done:false}];
  12. $scope.addTodo = function() {
  13. $scope.todos.push({text:$scope.todoText, done:false});
  14. $scope.todoText = '';
  15. };
  16. $scope.remaining = function() {
  17. var count = 0;
  18. angular.forEach($scope.todos, function(todo) {
  19. count += todo.done ? 0 : 1;
  20. });
  21. return count;
  22. };
  23. $scope.archive = function() {
  24. var oldTodos = $scope.todos;
  25. $scope.todos = [];
  26. angular.forEach(oldTodos, function(todo) {
  27. if (!!todo.done) $scope.todos.push(todo);
  28. });
  29. };
  30. }!
  31. !TrappedTodo methodsFor: 'accessing'!
  32. remaining
  33. ^self todosNotDone size
  34. !
  35. title
  36. ^title
  37. !
  38. title: aString
  39. title := aString
  40. !
  41. todoText
  42. ^todoText
  43. !
  44. todoText: aString
  45. todoText := aString
  46. !
  47. todos
  48. ^todos
  49. !
  50. todos: anArray
  51. todos := anArray
  52. !
  53. todosNotDone
  54. ^self todos reject: [ :each | each at: 'done' ]
  55. ! !
  56. !TrappedTodo methodsFor: 'action'!
  57. addTodo
  58. self todos add: #{'text'->self todoText. 'done'->false}.
  59. self todoText: ''
  60. !
  61. archive
  62. self todos: self todosNotDone
  63. ! !
  64. !TrappedTodo methodsFor: 'initialization'!
  65. initialize
  66. | axon |
  67. super initialize.
  68. axon := SimpleAxon new.
  69. axon addInterest: (TrappedPosition
  70. interestOn: #((todos) nil)
  71. block: [ axon changed: #((remaining)) ]).
  72. [ self axes: #((todos)) transform: [{
  73. #{'text'->'learn trapped'. 'done'->true}.
  74. #{'text'->'build a trapped app'. 'done'->false}
  75. }]] valueWithTimeout: 2000.
  76. title := 'Todo'.
  77. todoText := nil.
  78. todos := nil.
  79. self axxord: axon
  80. ! !
  81. !TrappedProcessor class methodsFor: '*Trapped-Todo'!
  82. classDoneXxx
  83. "This processor is not used any more,
  84. it was replaced by generic
  85. (replace ^ with ^done-) (attr class)
  86. in HTML.
  87. This example is left here to show how you can create quick
  88. toView-only processor without class by just passing a block"
  89. ^self dataToView: [ :carrier | carrier target class: 'done-', carrier value ]
  90. ! !