Tôi đang bắt đầu phát triển WebOS và tôi có nghi ngờ về nơi tôi nên bắt đầu và dừng người nghe ? Tôi đang đọc this sách nhưng tôi không thể tìm thấy lời giải thích rõ ràng về điều này. Trong ví dụ, tác giả thiết lập các bộ nghe trong hàm cài đặt nhưng tôi tự hỏi tại sao? không phải là một ý tưởng tốt hơn để đặt chúng trong chức năng kích hoạt và ngăn chặn chúng trong chức năng tắt kích hoạt như đề xuất bởi các ý kiến của mẫu?Bắt đầu và dừng người nghe trong khung công tác Mojo (WebOS)
Trong trường hợp tôi sai loại events nên và không nên đưa vào thiết lập và kích hoạt chức năng?
Khi thiết lập chính xác, kích hoạt, hủy kích hoạt, chức năng dọn dẹp được gọi?
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);
};