"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
 * Classes which implement this interface can bind
 * specific control elements to publish messages
 */
var IBehaviour = /** @class */ (function () {
    function IBehaviour(target, bindings) {
        var _this = this;
        this.channelId = null;
        this.isValueValid = function (value) {
            return _this.channelId && _this.subscription && value.replace(/^\s+|\s+$/g, "") !== "";
        };
        this.target = target;
        this.subscription = null;
        this.bindings = Array.isArray(bindings) ? bindings : [bindings];
    }
    IBehaviour.prototype.init = function (channelId) {
        this.channelId = channelId;
    };
    /**
     * Adds event listeners to the invoker.
     * The user is able to publish a message by
     * clicking the invoker.
     *
     * @param gateway the {@link Subscription}
     */
    IBehaviour.prototype.bind = function (gateway) {
        var _this = this;
        this.subscription = gateway;
        this.bindings.forEach(function (binding) {
            _this.target.addEventListener(binding.type, binding.handler, true);
        });
    };
    /**
     * Removes the active event listeners
     */
    IBehaviour.prototype.unbind = function () {
        var _this = this;
        this.bindings.forEach(function (binding) {
            _this.target.removeEventListener(binding.type, binding.handler, true);
        });
    };
    return IBehaviour;
}());
exports.IBehaviour = IBehaviour;
//# sourceMappingURL=IBehaviour.js.map