Eventlistener module base
This commit is contained in:
parent
c92a293d31
commit
600eed9dbc
|
@ -8,12 +8,13 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import Module from './module';
|
||||
import Events from './events';
|
||||
|
||||
export default class {
|
||||
export default class extends Module {
|
||||
|
||||
constructor() {
|
||||
for (let event of this.events) {
|
||||
events() {
|
||||
for (let event of this.eventBindings) {
|
||||
Events.on(event.id, event.callback);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,10 +20,10 @@ export default class Module {
|
|||
args
|
||||
}
|
||||
this.setState = this.setState.bind(this);
|
||||
this.init();
|
||||
this.initialize();
|
||||
}
|
||||
|
||||
init() {
|
||||
initialize() {
|
||||
if (this.bindings) this.bindings();
|
||||
if (this.setInitialState) this.setInitialState(this.state);
|
||||
if (this.events) this.events();
|
||||
|
|
|
@ -16,9 +16,9 @@ import { ProfileBadges } from 'ui';
|
|||
export default class {
|
||||
|
||||
static get modules() {
|
||||
return [
|
||||
ProfileBadges
|
||||
];
|
||||
return this._modules ? this._modules : (this._modules = [
|
||||
new ProfileBadges()
|
||||
]);
|
||||
}
|
||||
|
||||
static initModules() {
|
||||
|
|
|
@ -7,3 +7,4 @@ export { default as Globals } from './globals';
|
|||
export { default as Vendor } from './vendor';
|
||||
export { default as WebpackModules } from './webpackmodules';
|
||||
export { default as ModuleManager } from './modulemanager';
|
||||
export { default as EventListener } from './eventlistener';
|
|
@ -17,7 +17,6 @@ import { Utils } from 'common';
|
|||
export default class {
|
||||
|
||||
static initUiEvents() {
|
||||
//this.profilePopupModule.open
|
||||
const defer = setInterval(() => {
|
||||
if (!this.profilePopupModule) return;
|
||||
clearInterval(defer);
|
||||
|
|
|
@ -8,18 +8,24 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import { EventListener } from 'modules';
|
||||
import DOM from './dom';
|
||||
import { BdBadge } from './components/bd';
|
||||
import VueInjector from './vueinjector';
|
||||
import { Events } from 'modules';
|
||||
|
||||
export default class {
|
||||
export default class extends EventListener {
|
||||
|
||||
static init() {
|
||||
Events.on('ui-event', this.uiEvent.bind(this));
|
||||
bindings() {
|
||||
this.uiEvent = this.uiEvent.bind(this);
|
||||
}
|
||||
|
||||
static uiEvent(e) {
|
||||
get eventBindings() {
|
||||
return [
|
||||
{ id: 'ui-event', callback: this.uiEvent }
|
||||
];
|
||||
}
|
||||
|
||||
uiEvent(e) {
|
||||
const { event, data } = e;
|
||||
if (event !== 'profile-popup-open') return;
|
||||
const { userid } = data;
|
||||
|
@ -28,7 +34,7 @@ export default class {
|
|||
this.inject(userid);
|
||||
}
|
||||
|
||||
static inject(userid) {
|
||||
inject(userid) {
|
||||
const c = this.contributors.find(c => c.id === userid);
|
||||
if (!c) return;
|
||||
|
||||
|
@ -52,11 +58,7 @@ export default class {
|
|||
}, 400);
|
||||
}
|
||||
|
||||
static filter(mutation) {
|
||||
return mutation.target.firstChild && mutation.target.className.includes('modal');
|
||||
}
|
||||
|
||||
static get contributors() {
|
||||
get contributors() {
|
||||
return [
|
||||
{ 'id': '81388395867156480', 'webdev': true, 'developer': true, 'contributor': true }, // Jiiks
|
||||
{ 'id': '98003542823944192', 'webdev': false, 'developer': true, 'contributor': true }, // Pohky
|
||||
|
|
Loading…
Reference in New Issue