JSFiddle - React, Tailwind, and code Playground

by rcuzcano

JavaScript

var WidgetSettings = {
    handlers: [],  // observers
    _GUID: "",
    _dataType: "",
    // this._displaySettings;
    // this._lstLegend;
    _currentRepresentation: "",
    // this._allowedRepresentations;

    changeCurrentRepresentation: function (name) {
        this._currentRepresentation = name;
        this.dispatch("changeRep");
    },
    changeGuid: function (guid) {
        this._GUID = guid;
        this.dispatch("changeGUID");
    },

    subscribe: function (eventName, listener) {
        if (!this.handlers[eventName]) this.handlers[eventName] = [];
        this.handlers[eventName].push(listener);
    },
    unsubscribe: function (handler) {
        this.handlers = this.handlers.filter(
        function (item) {
            if (item !== handler) {
                return item;
            }
        }
        );
    },
    dispatch: function (eventName) {
        if (this.handlers[eventName])
            for (var i = 0; i < this.handlers[eventName].length; i++) {
                this.handlers[eventName][i](this);
            }
    },
    get: function () {
        return this;
    }
}

WidgetSettings.subscribe("changeRep", function () {
    alert("new representation:" + WidgetSettings.get()._currentRepresentation);
});
WidgetSettings.subscribe("changeGUID", function () {
    alert("new GUID:" + WidgetSettings.get()._GUID);
});

WidgetSettings.changeCurrentRepresentation("pie");
WidgetSettings.changeGuid("newGUID");var WidgetSettings = {
    handlers: [],  // observers
    _GUID: "",
    _dataType: "",
    // this._displaySettings;
    // this._lstLegend;
    _currentRepresentation: "",
    // this._allowedRepresentations;

    changeCurrentRepresentation: function (name) {
        this._currentRepresentation = name;
        this.dispatch("changeRep");
    },
    changeGuid: function (guid) {
        this._GUID = guid;
        this.dispatch("changeGUID");
    },

    subscribe: function (eventName, listener) {
        if...