szurubooru/client/js/controllers/page_controller.js
rr- 2a4241641c client/events: improve event dispatching
This commit introduces timer-less retry system:

1. Any change to URL is going to stop listening to any messages.
2. If a message is sent and there's no handler that could pick it up,
   the message gets enqueued.
3. The message is sent again to the first handler that attaches itself
   to given event type.

While in theory this is full of holes (no control over the first
handler), in practice, it works quite well.

Additionally, views.listenToMessages was attaching to completely wrong
DOM node; this commit fixes this as well.
2016-05-11 23:47:50 +02:00

35 lines
808 B
JavaScript

'use strict';
const events = require('../events.js');
const settings = require('../settings.js');
const EndlessPageView = require('../views/endless_page_view.js');
const ManualPageView = require('../views/manual_page_view.js');
class PageController {
constructor() {
events.listen(events.SettingsChange, () => {
this.update();
return true;
});
this.update();
}
update() {
if (settings.getSettings().endlessScroll) {
this.pageView = new EndlessPageView();
} else {
this.pageView = new ManualPageView();
}
}
run(ctx) {
this.pageView.unrender();
this.pageView.render(ctx);
}
stop() {
this.pageView.unrender();
}
}
module.exports = new PageController();