Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bind(One/All) callback #78

Closed
kenjiqq opened this issue Jun 25, 2014 · 4 comments
Closed

Bind(One/All) callback #78

kenjiqq opened this issue Jun 25, 2014 · 4 comments
Assignees
Milestone

Comments

@kenjiqq
Copy link

kenjiqq commented Jun 25, 2014

Would it be possible to have a callback to this function that would be run when the resources have been changed? It might be that you want to do some more processing of the data when it has changed, and while you could run a watchCollection on the scope value that is set in the bindAll method that seems like a wasted watch.

@kentcdodds
Copy link
Contributor

👍

@jmdobry
Copy link
Member

jmdobry commented Jun 25, 2014

I can add that, but if you're wanting more control, couldn't you just do:

$scope.$watch(function () {
  return DS.lastModified('post');
}, function () {
  $scope.posts = DS.filter('post', params);
  // do other processing on posts
});

This is all that bindAll does internally. In addition, the above example lets you have a more advanced $watch and dynamic params, when you're doing pagination, for example.

var PAGE_SIZE = 20;
$scope.currentPage = 0;

$scope.$watch(function () {
  return DS.lastModified('post') + $scope.currentPage;
}, function () {
  $scope.posts = DS.filter('post', {
    limit: PAGE_SIZE,
    skip: $scope.currentPage * PAGE_SIZE
  });
  // do other processing on posts
});

@jmdobry jmdobry self-assigned this Jun 25, 2014
@jmdobry jmdobry mentioned this issue Jun 25, 2014
9 tasks
@jmdobry jmdobry added 3 - Done and removed question labels Jun 25, 2014
@kenjiqq
Copy link
Author

kenjiqq commented Jun 25, 2014

I guess i could do that as well that is very true.

I have a kind of unrelated question but i will ask it here anyways, can you invalidate a resource so that any future findAll requestion to that resource won't hit the cache? Does ejectAll that resource also clear the query history?

@jmdobry
Copy link
Member

jmdobry commented Jun 25, 2014

That's a good point, ejectAll should clear the query history. You can pass an option to findAll called bypassCache and it will send the query to the server regardless of whether it has been made before.

@jmdobry jmdobry added this to the 0.10.0 milestone Jun 26, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants