UNPKG

app-decorators

Version:

Collection of useful ES7 Decorators, writtin in ES6, that can be used for building webapps

118 lines (93 loc) 2.98 kB
System.register(['app-decorators/src/libs/element-to-function', '../helpers/trigger', '../datas/init-maps', '../libs/random-storage'], function (_export, _context) { "use strict"; var _elementToFunc, trigger, initCoreMap, storage, customElementHooks; /** * getComponentName * @returns {string} name */ function getComponentName() { var localName = this.localName; var isValue = this.getAttribute('is'); return localName + (isValue ? '[is="' + isValue + '"]' : ''); } /** * init * @param callbackName {string} * @param callbacks {function[]} * @param vars {object} */ function init(callbackName) { var _this = this; var callbacks = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [function () {}]; var vars = arguments[2]; callbacks.forEach(function (cb) { return cb(_this, vars); }); this[callbackName] ? this[callbackName](vars) : null; trigger.call(this, callbackName, vars); } /** * component {function} * @param {object} settings */ function component() { var settings = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; /** * decorator * @param {function} ComponentClass */ return function (Class) { initCoreMap(storage, Class); var map = storage.get(Class); map.set('@component', settings); var _iteratorNormalCompletion = true; var _didIteratorError = false; var _iteratorError = undefined; try { var _loop = function _loop() { var callbackName = _step.value; Class.prototype[callbackName + 'Callback'] = function (vars) { // get also vars from dom-attributes: // see: https://github.com/SerkanSipahi/app-decorators/issues/28 var callbacks = map.get('@callbacks').get(callbackName); init.call(this, callbackName, callbacks, vars); }; }; for (var _iterator = customElementHooks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { _loop(); } } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator.return) { _iterator.return(); } } finally { if (_didIteratorError) { throw _iteratorError; } } } }; } return { setters: [function (_appDecoratorsSrcLibsElementToFunction) { _elementToFunc = _appDecoratorsSrcLibsElementToFunction.default; }, function (_helpersTrigger) { trigger = _helpersTrigger.trigger; }, function (_datasInitMaps) { initCoreMap = _datasInitMaps.initCoreMap; }, function (_libsRandomStorage) { storage = _libsRandomStorage.storage; }], execute: function () { customElementHooks = ['created', 'attached', 'detached', 'attributeChanged']; _export('init', init); _export('component', component); _export('getComponentName', getComponentName); } }; }); //# sourceMappingURL=component.js.map