0
我从使用Firebase的黑客新闻API获取最新消息。我打算构建一个渐进式网络应用程序,因此,我打算将结果缓存到本地存储中。在渐进式网络应用程序中处理Firebase实时更改
当前的代码是here,它获取并呈现顶级报道。该代码是在这里:
var ref = new Firebase("http://hacker-news.firebaseio.com/v0/");
var itemRef = ref.child('item');
var topStories = [];
var storyCallback = function(snapshot) {
var story = snapshot.val();
var html = '';
if(story.score) {
html = '<i>'+story.score+'</i> <a href="'+story.url+'" id="article_a">'+story.title+'</a>'
}
document.getElementById(topStories.indexOf(story.id)).innerHTML = html;
}
ref.child('topstories').once('value', function(snapshot) {
topStories = snapshot.val();
for(var i = 0; i < topStories.length; i++) {
var element = document.createElement("P");
element.id = i;
document.getElementById('items').appendChild(element);
itemRef.child(topStories[i]).on('value', storyCallback);
}
});
ref.child('topstories').on('child_changed', function(snapshot, prevChildName) {
var ref = snapshot.ref()
var index = ref.name();
var oldItemId = topStories[index];
itemRef.child(oldItemId).off();
var newItemId = snapshot.val();
topStories[index] = newItemId
itemRef.child(newItemId).on('value', storyCallback);
});
如果我添加的每个故事到localStorage的(通过调整上面的代码),我怎么能跳过从火力下一次获取它(如果它已经呈现,并且不改变) ?
请注意,不改变部分是重要的,因为我可以很容易地从本地存储使用密钥获取,它应该如何与firebase同步。所以,想知道是否火力有一些方法来处理这