export default class BaseModule {

    constructor({ eventBus, store, api, context }) {

        this.eventBus = eventBus;
        this.store = store;
        this.api = api;
        this.context = context;

        this.views = new Map();
        this.activeView = null;

    }

    async init() {
        // optional override
    }

    async openView(ViewClass, container) {

        if (this.activeView) {
            this.activeView.destroy();
        }

        const view = new ViewClass({
            eventBus: this.eventBus,
            store: this.store,
            tab: this.context.tab
        });

        this.activeView = view;

        await view.render(container);

    }

    destroy() {

        if (this.activeView) {
            this.activeView.destroy();
        }

        this.views.clear();

    }

}
