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

Auto-sync children key models if $sync is called on the parent #73

Open colinmacdonald opened 10 years ago

colinmacdonald commented 10 years ago
$scope.todos = $goKey('todos').$sync();

$scope.todos.$on('ready', function() {
  var myTodo = $scope.todos.$key('id-1231231adasd-000');
  // myTodo.desc === 'test test'
  // myTodo.complete === false
});

We already have this data sync'd on the parent, should make it easier to work with child key models.

colinmacdonald commented 10 years ago

This could be quite useful if using with $save on a specific child node (when we have it) instead of having to $sync first. Thinking something like:

  $scope.todos = $goKey('todos').$sync();

  $scope.editTodo = function(id, desc) {
    var todo = $scope.todos.$key(id);
    todo.desc = desc;
    todo.complete = !todo.complete;

    todo.$save();
  };

to prevent children from being sync'd automatically we could have an option on either the parent sync

  var todos = $goKey('todos').$sync({capture: true}); // default capture === false

or when creating a new model on a child

  var todo = todos.$key('id-1231y182u12b-000', { sync: true/false });