Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

provide disassociate callback #34

Merged
merged 1 commit into from
Jun 18, 2013
Merged

Conversation

clkao
Copy link
Contributor

@clkao clkao commented May 26, 2013

Make the promise returned by angularFire resolved with a callback that disassociate the instance, by calling dataRef.off and unregistering $scope.$watch.

This breaks the existing promise API. But since angularFire is to bind an object onto scope, it doesn't seem to be useful to get the same value from the promise though.

@anantn
Copy link
Contributor

anantn commented May 28, 2013

@clkao - Thanks for sending in the pull request! Before merging it however, I'd like to understand the motivations behind the patch a little better. Since it'll break our API I'm quite hesitant to make the change.

@clkao
Copy link
Contributor Author

clkao commented May 29, 2013

@anantn, the use case is when a controller has a $scope variable bound to specified resource, such $scope.project to /project/foo, you can't change that binding to /project/bar. If you use angularFire to reassociate, content of foo will be overridden by bar. delete $scope.project and reassociate won't work either, because the $watch gets project being updated to null and will delete project/foo. That's why an explicit disassociation api is needed, for both off() the firebase ref and unwatch the scope variable.

@clkao
Copy link
Contributor Author

clkao commented Jun 17, 2013

Hi, any update on this?

@anantn
Copy link
Contributor

anantn commented Jun 18, 2013

Sorry this got slipped through the cracks. The API makes sense now, thanks for the explanation and pull request!

anantn added a commit that referenced this pull request Jun 18, 2013
provide disassociate callback
@anantn anantn merged commit 8cdd9f8 into FirebaseExtended:gh-pages Jun 18, 2013
@robertmaxwell
Copy link

How do you go about using this "disassociation api"?

I am trying to switch which angular resources I am using within a controller (exactly like @clkao's example use case) and it is deleting the data in Firebase.

How do I first disassociate the Firebase connection and Angular watcher so that I can assign a new resource/reference without this deletion?

thanks in advance

@clkao
Copy link
Contributor Author

clkao commented Jun 20, 2013

here's what i do before associating an entry:

// in $scope.$watch projectName
if (typeof $scope.cleanup === 'function') {
  $scope.cleanup();
}
promise = angularfire(hub.root.child("projects/" + projectName), $scope, 'project', {});
return promise.then(function(cb){
  return $scope.cleanup = cb;
});

@robertdimarco would you like to help adding that to the document?

full usage can be found at: https://github.com/g0v/hack.g0v.tw/blob/master/app/app/hub.ls#L93

@adamjgrant
Copy link

Also, @clkao, I tried implementing your solution, which did not work for me. Maybe I'm putting it in the wrong place? What is $scope.$watch, is that AngularFire or Angular? Whatever it is, I don't have or nor knew I needed it from the documentation.

Thanks.

@adamjgrant
Copy link

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants