6
我開始WebOS的開發,我有我應該從哪裏開始和停止我的聽衆 一個疑問? 我正在閱讀this書,但我無法找到關於此的明確解釋。在示例中,作者在設置函數中設置了監聽器,但是我想知道爲什麼?將它們設置爲激活函數並且按照模板的註釋建議的停用函數停止它們不是一個好主意嗎?開始在Mojo的框架停止監聽器(WebOS的)
如果我錯了,應該和不應該把什麼樣的events在安裝和激活功能?
當正好安裝,激活,停用,清除函數被調用?
StoryViewAssistant.prototype.setup = function() {
//HERE, OK?
this.nextStoryHandler = this.nextStory.bindAsEventListener(this);
this.previousStoryHandler = this.previousStory.bindAsEventListener(this);
this.controller.listen("nextStory", Mojo.Event.tap, this.nextStoryHandler);
this.controller.listen("previousStory", Mojo.Event.tap,this.previousStoryHandler);
/* add event handlers to listen to events from widgets */
};
StoryViewAssistant.prototype.activate = function(event) {
//HERE?
/* put in event handlers here that should only be in effect when this scene is active. For example, key handlers that are observing the document */
};
StoryViewAssistant.prototype.deactivate = function(event) {
//HERE?
/* remove any event handlers you added in activate and do any other cleanup that should happen before this scene is popped or another scene is pushed on top */
};
StoryViewAssistant.prototype.cleanup = function(event) {
//HERE, OK?
this.controller.stopListening("nextStore", Mojo.Event.tap, this.nextStoryHandler);
};