UNPKG

app-decorators

Version:

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

97 lines (77 loc) 3.17 kB
System.register(['app-decorators/src/libs/element-to-function', '../apps/router', '../datas/init-maps', '../libs/random-storage'], function (_export, _context) { "use strict"; var _elementToFunc, Router, initCoreMap, initActionMap, storage; /** * action * @param {string} route * @return {Function} */ function action(route) { if (!route) { throw new Error('Please pass an action'); } return function (_ref, method, _ref2) { var constructor = _ref.constructor; var value = _ref2.value; var Class = constructor; initCoreMap(storage, Class); initActionMap(storage, Class); var map = storage.get(Class); map.get('@action').get('events').push([method + ' ' + route, value]); /** * ### Ensure "registerCallback('created', ..." (see below) registered only once ### * This function will called every time if an event registered e.g. @on('click .foo') * but registerOnCreatedCallback can only call once because we want only Create * one Eventhandler */ if (map.get('@action').get('callbacksDefined')) { return; } map.get('@callbacks').get('created').push(function (domNode) { var events = map.get('@action').get('events'); domNode.$router = Router.create({ routes: events, scope: domNode, bind: domNode }); }); map.get('@callbacks').get('attached').push(function (domNode) { if (domNode.$router.initialized()) { return; } var events = map.get('@action').get('events'); var config = Router.makeConfig({ routes: events, scope: domNode, bind: domNode }); /** * Using the same instance is 30% faster in * (Chrome, Opera) and no difference in Firefox * @see: https://jsperf.com/new-class-vs-singleton */ domNode.$router.reinit(config); }); map.get('@callbacks').get('detached').push(function (domNode) { domNode.$router.destroy(); }); map.get('@action').set('callbacksDefined', true); }; } return { setters: [function (_appDecoratorsSrcLibsElementToFunction) { _elementToFunc = _appDecoratorsSrcLibsElementToFunction.default; }, function (_appsRouter) { Router = _appsRouter.Router; }, function (_datasInitMaps) { initCoreMap = _datasInitMaps.initCoreMap; initActionMap = _datasInitMaps.initActionMap; }, function (_libsRandomStorage) { storage = _libsRandomStorage.storage; }], execute: function () { _export('action', action); } }; }); //# sourceMappingURL=action.js.map