app-decorators
Version:
Collection of useful ES7 Decorators, writtin in ES6, that can be used for building webapps
78 lines (62 loc) • 2.01 kB
JavaScript
System.register(["app-decorators/src/libs/element-to-function"], function (_export, _context) {
"use strict";
var _elementToFunc, _createClass, Pubsub;
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
return {
setters: [function (_appDecoratorsSrcLibsElementToFunction) {
_elementToFunc = _appDecoratorsSrcLibsElementToFunction.default;
}],
execute: function () {
_createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
_export("Pubsub", Pubsub = function () {
function Pubsub(config) {
_classCallCheck(this, Pubsub);
this.scope = {};
Object.assign(this, config);
}
_createClass(Pubsub, [{
key: "publish",
value: function publish(event) {
var _scope;
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
(_scope = this.scope).trigger.apply(_scope, [event].concat(args));
}
}, {
key: "subscribe",
value: function subscribe(event, callback) {
this.scope.on(event, callback);
}
}, {
key: "unsubscribe",
value: function unsubscribe(event) {
this.scope.off(event);
}
}]);
return Pubsub;
}());
_export("Pubsub", Pubsub);
}
};
});
//# sourceMappingURL=pubsub.js.map