7342e016-2a09-4533-832a-48caa29d9b90.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. "use strict";
  2. cc._RF.push(module, '7342eAWKglFM4MqSMqinZuQ', 'BaseMediator');
  3. // lightMVC/core/base/BaseMediator.ts
  4. "use strict";
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. var Facade_1 = require("../Facade");
  7. var NotificationManager_1 = require("../manager/NotificationManager");
  8. var CommandManager_1 = require("../manager/CommandManager");
  9. /**
  10. * 视图中介者基类
  11. * @author Yue
  12. * @description 生命周期
  13. * BaseMediator.init
  14. * BaseView.__init__
  15. * BaseMediator.viewDidAppear
  16. */
  17. var BaseMediator = /** @class */ (function () {
  18. function BaseMediator() {
  19. }
  20. /**
  21. * 内部初始化使用,外部不要调用。
  22. * @private
  23. */
  24. BaseMediator.prototype.__init__ = function () {
  25. this._notiMap = new Map();
  26. };
  27. /**
  28. * 绑定UI事件,接收view层派发的事件。
  29. * @param {string} name 事件名称
  30. * @param {(any)=>void} cb 事件回调
  31. * @param {BaseMediator} target 回调绑定对象
  32. */
  33. BaseMediator.prototype.bindEvent = function (name, cb, target) {
  34. this.view.__bindEvent__(name, cb, target);
  35. };
  36. /**
  37. * 注册消息监听
  38. * @param {string} noti 通知key值
  39. * @param {(data: any)=>void} cb 通知监听的回调函数
  40. * @param {Object} target 回调绑定的对象
  41. */
  42. BaseMediator.prototype.registerNoti = function (noti, cb, target) {
  43. this._notiMap.set(noti, { key: noti, cb: cb, target: target });
  44. };
  45. BaseMediator.prototype.deleteKey = function (noti) {
  46. this._notiMap.delete(noti);
  47. };
  48. /**
  49. * 发送消息通知
  50. * @param {string} noti 通知key值
  51. * @param {Object} body 消息传递的参数
  52. */
  53. BaseMediator.prototype.sendNoti = function (noti, body) {
  54. NotificationManager_1.default.getInstance().__sendNotification__(noti, body);
  55. };
  56. /**
  57. * 发送命令接口
  58. * @param {{new (): BaseCommand}} cmd 命令类
  59. * @param {Object} data 命令参数
  60. */
  61. BaseMediator.prototype.sendCmd = function (cmd, data) {
  62. CommandManager_1.default.getInstance().__executeCommand__(cmd, data);
  63. };
  64. /**
  65. * 打开新场景
  66. * @param mediator
  67. * @param view
  68. * @param data {Object} data 自定义的任意类型透传数据。(可选)
  69. */
  70. BaseMediator.prototype.runScene = function (mediator, view, data) {
  71. Facade_1.Facade.getInstance().runScene(mediator, view, data);
  72. };
  73. /**
  74. * 返回上一场景
  75. * @returns {boolean}是否存在上一个场景
  76. */
  77. BaseMediator.prototype.backScene = function () {
  78. return Facade_1.Facade.getInstance().backScene();
  79. };
  80. /**
  81. * 打开view界面
  82. * @param {{new(): BaseMediator}} mediator 界面mediator类型,类类型。
  83. * @param {{new(): BaseView}} view view 场景mediator类型,类类型。
  84. * @param {Object} data 自定义的任意类型透传数据。(可选)
  85. */
  86. BaseMediator.prototype.popView = function (mediator, view, data) {
  87. Facade_1.Facade.getInstance().popView(mediator, view, data);
  88. };
  89. /**
  90. * 添加层级
  91. * @param {{new(): BaseMediator}} mediator 界面mediator类型,类类型。
  92. * @param {{new(): BaseView}} view view 场景mediator类型,类类型。
  93. * @param {number} zOrder 层级。(可选)
  94. * @param {Object} data 自定义的任意类型透传数据。(可选)
  95. */
  96. BaseMediator.prototype.addLayer = function (mediator, view, zOrder, data) {
  97. Facade_1.Facade.getInstance().addLayer(mediator, view, zOrder, data);
  98. };
  99. /**
  100. * 获取model对象
  101. * @param {{new (): BaseModel}} model
  102. */
  103. BaseMediator.prototype.getModel = function (model) {
  104. return Facade_1.Facade.getInstance().getModel(model);
  105. };
  106. return BaseMediator;
  107. }());
  108. exports.default = BaseMediator;
  109. cc._RF.pop();