import EventBus from "../Events/EventBus";
import Events from "../Events/Events";

let instance;
const instanceKey = 'data_392994';

class Storage {

    _showingProductsCount = 0;
    showingProductsDelay = 400;

    constructor(key) {
        if (key !== instanceKey) {
            throw new Error('Cannot instantiate like this');
        }
    }

    setShowingProductsCount(count) {
        this._showingProductsCount = count;
        EventBus.getInstance().triggerEvent(Events.SHOWING_PRODUCTS_COUNT, {
            count: this._showingProductsCount
        });
    }

    getShowingProductsCount() {
        return this._showingProductsCount;
    }

    static getInstance() {
        if (!instance) {
            instance = new Storage(instanceKey);
        }
        return instance;
    }
}

export default Storage;