Created
February 22, 2013 19:23
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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; | |
}); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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