Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

58 rindas
1.1 KiB

  1. define([
  2. 'js/system/events',
  3. 'js/system/globals'
  4. ], function (
  5. events,
  6. globals
  7. ) {
  8. const hookEvent = function (e, cb) {
  9. if (!this.eventList[e])
  10. this.eventList[e] = [];
  11. this.eventList[e].push(cb);
  12. events.on(e, cb);
  13. };
  14. const unhookEvents = function () {
  15. Object.entries(this.eventList).forEach(([eventName, callbacks]) => {
  16. callbacks.forEach(c => events.off(eventName, c));
  17. });
  18. };
  19. return {
  20. templates: {},
  21. init: function () {
  22. let cpns = globals.clientConfig.clientComponents;
  23. return Promise.all(cpns.map(c => this.getComponent(c)));
  24. },
  25. getComponent: function (cpn) {
  26. return new Promise(resolve => {
  27. require([cpn.path], this.onGetComponent.bind(this, resolve, cpn));
  28. });
  29. },
  30. onGetComponent: function (resolve, cpn, template) {
  31. template.eventList = {};
  32. template.hookEvent = hookEvent;
  33. template.unhookEvents = unhookEvents;
  34. this.templates[cpn.type] = template;
  35. resolve();
  36. },
  37. getTemplate: function (type) {
  38. if (type === 'lightpatch')
  39. type = 'lightPatch';
  40. let template = this.templates[type] || {
  41. type: type
  42. };
  43. return template;
  44. }
  45. };
  46. });