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同步。所以,想知道是否火力有一些方法來處理這