在main.js
内,我创建了一个Panel
ui.html
包含js
源文件,其中我会收听来自Panel
的邮件
我从未看到restoring
转储控制台,为什么这个函数从未被调用过?
panel = PanelAPI.Panel({
width: 300,
height: 400,
contentURL: Data.get("html/ui.html")
});
panel.port.emit('previousHistory', SimpleStorage.getHistory(), SimpleStorage.getCurrentHistoricalEntry());
panel.port.on("historyUpdate", function (history, currentHistoricalEntry) {
SimpleStorage.setHistory(history);
SimpleStorage.setCurrentHistoricalEntry(currentHistoricalEntry);
});
contentURL: Data.get("html/ui.html")
,js
文件包含此内容以收听消息..
addon.port.on("previousHistory", function(history, currentHistoricalEntry) {
console.log("restoring");
Namespace.restoreHistory(history, currentHistoricalEntry);
});
SimpleStorage.js
,是我处理simple-storage
api ..
var ss = require("sdk/simple-storage");
exports.getHistory = function(){
console.log("retrieving ss: " + ss.storage.history)
return ss.storage.history;
}
exports.setHistory = function(history){
ss.storage.history = history;
console.log("history in ss is now: " + ss.storage.history)
}
exports.setCurrentHistoricalEntry = function(currentHistoricalEntry){
ss.storage.currentHistoricalEntry = currentHistoricalEntry;
console.log("currhisent is now" + ss.storage.currentHistoricalEntry);
}
exports.getCurrentHistoricalEntry = function(){
console.log("retrieving ss.currentr: " + ss.storage.currentHistoricalEntry);
return ss.storage.currentHistoricalEntry;
}
答案 0 :(得分:1)
将this.port.emit('previousHistory', prefs);
移至Panel.onShow()
工作..
panel = PanelAPI.Panel({
width: 300,
height: 400,
contentURL: Data.get("html/ui.html"),
onShow: function() {
var prefs = JSON.stringify({
history: SimpleStorage.getHistory(),
currentHistoricalEntry: SimpleStorage.getCurrentHistoricalEntry()
});
this.port.emit('previousHistory', prefs);
}
});