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);
};