goinstant / goangular

AngularJS bindings for GoInstant. Build realtime, multi-user apps with AngularJS and GoInstant easily. https://developers.goinstant.com/v1/GoAngular/index.html
BSD 3-Clause "New" or "Revised" License
137 stars 30 forks source link

$on triggers too early, before model is actually updated #71

Open colinmacdonald opened 10 years ago

colinmacdonald commented 10 years ago
$scope.messages = $goKey('messages');
$scope.messages.$add({ text: 'abc123' });
$scope.messages.$on('add', { local: true, listener: function(val, con) {
  console.log(val, con, $scope.messages); // val does not exist yet in $scope.messages
}});

I would expect the model to contain the new message when $on is triggered.

hvdklauw commented 10 years ago

Can confim this happening.

For the sorting of the result from $goQuery I tried to use $key (before this returned the wrong $sync thing, which is now fixed) and was using the $on('ready', ...) to push the synced model to the array. Almost every time AngularJS complains about duplicates in the array and that I need to add a track by (which is there but references a undefined item).

colinmacdonald commented 10 years ago

Thanks for the feedback. This issue and the entire event system is planned to be reworked for release v3.3.0.