2 Commits d44551bcea ... ea3e8cc6c7

Author SHA1 Message Date
  Herbert Vojčík ea3e8cc6c7 Counter example uses DirectTrapper. 6 years ago
  Herbert Vojčík 6cc2fd6bda DirectTrapper not writing if new value not different. 6 years ago

+ 1 - 1
example-counter/src/Trapped-Counter.js

@@ -7,7 +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.IsolatingTrapper, [], "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");

+ 1 - 1
example-counter/src/Trapped-Counter.st

@@ -1,5 +1,5 @@
 Smalltalk createPackage: 'Trapped-Counter'!
-IsolatingTrapper subclass: #App
+DirectTrapper subclass: #App
 	instanceVariableNames: ''
 	package: 'Trapped-Counter'!
 !App commentStamp!

+ 7 - 3
src/Trapped-Backend.js

@@ -645,13 +645,17 @@ var newValue,eavModel;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
+var $1;
 eavModel=$recv(path)._asEavModel();
 newValue=$recv(aBlock)._value_($recv(eavModel)._on_($self["@payload"]));
 $recv((function(){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx2) {
 //>>excludeEnd("ctx");
+$1=$recv($self["@payload"]).__eq_eq(newValue);
+if(!$core.assert($1)){
 return $recv(eavModel)._on_put_($self["@payload"],newValue);
+}
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
 //>>excludeEnd("ctx");
@@ -661,7 +665,7 @@ return $core.withContext(function($ctx2) {
 //>>excludeEnd("ctx");
 return $self._changed_(path);
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,3)});
 //>>excludeEnd("ctx");
 }));
 return self;
@@ -671,10 +675,10 @@ return self;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["path", "aBlock"],
-source: "modify: path do: aBlock\x0a    | newValue eavModel |\x0a    eavModel := path asEavModel.\x0a    newValue := aBlock value: (eavModel on: payload).\x0a    [ eavModel on: payload put: newValue ] ensure: [ self changed: path ]",
+source: "modify: path do: aBlock\x0a    | newValue eavModel |\x0a    eavModel := path asEavModel.\x0a    newValue := aBlock value: (eavModel on: payload).\x0a    [ payload == newValue ifFalse: [ eavModel on: payload put: newValue ] ] ensure: [ self changed: path ]",
 referencedClasses: [],
 //>>excludeEnd("ide");
-messageSends: ["asEavModel", "value:", "on:", "ensure:", "on:put:", "changed:"]
+messageSends: ["asEavModel", "value:", "on:", "ensure:", "ifFalse:", "==", "on:put:", "changed:"]
 }),
 $globals.DirectTrapper);
 

+ 1 - 1
src/Trapped-Backend.st

@@ -193,7 +193,7 @@ modify: path do: aBlock
     | newValue eavModel |
     eavModel := path asEavModel.
     newValue := aBlock value: (eavModel on: payload).
-    [ eavModel on: payload put: newValue ] ensure: [ self changed: path ]
+    [ payload == newValue ifFalse: [ eavModel on: payload put: newValue ] ] ensure: [ self changed: path ]
 !
 
 read: path do: aBlock