[英]addon.port.on not recieving message from addon
Inside main.js
I create a Panel
. 在main.js
内部,我创建了一个Panel
。
ui.html
includes a js
source file and in it I listen for messages from Panel
. ui.html
包含一个js
源文件,并且在其中侦听来自Panel
消息。
I never see restoring
dumped the console, why is this function never called? 我从没见过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
file includes this to listen for messages .. contentURL: Data.get("html/ui.html")
, js
文件包括此内容以侦听消息。
addon.port.on("previousHistory", function(history, currentHistoricalEntry) {
console.log("restoring");
Namespace.restoreHistory(history, currentHistoricalEntry);
});
SimpleStorage.js
, is where I handle access to simple-storage
api .. 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;
}
Moving this.port.emit('previousHistory', prefs);
移动this.port.emit('previousHistory', prefs);
into Panel.onShow()
worked .. 进入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);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.