Skip to content

Instantly share code, notes, and snippets.

@eduardordm
Created February 22, 2013 19:23
Show Gist options
  • Save eduardordm/5015899 to your computer and use it in GitHub Desktop.
Save eduardordm/5015899 to your computer and use it in GitHub Desktop.
AngularJS ephemeral caching. Consider a list of links containing which represent folders. Just like an email client, the user will browser between folders. ng-clicks will trigger switchFolder
$scope.switchFolder = function(attrs) {
// Results found on the last query will be available instantly (if any)
// you could also add a Message.is_query_cached to check if there are cached results
$scope.messages = Message.query_cached({ id: attr.some_id});
// Lets find the actual results, which can take longer
var messages = Message.query({ id: attr.some_id}, function () {
$scope.messages = message;
});
}
$scope.switchFolder = function(attrs) {
// You would usually do this, but it can break UX sometimes
$scope.messages = Message.query({id: attrs.some_id});
}
$scope.switchFolderBlocking = function(attrs) {
// This way the user will still have the current data while you are grabbing more
var messages = Message.query({id: attrs.some_id}, function () {
$scope.messages = message;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment