70817a9e-179f-4c3a-a860-25732bfbebd1.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. "use strict";
  2. cc._RF.push(module, '70817qeF59MOqhgJXMr++vR', 'ModelManager');
  3. // lightMVC/core/manager/ModelManager.ts
  4. "use strict";
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. var ModelManager = /** @class */ (function () {
  7. /**
  8. * @constructor
  9. * @private
  10. */
  11. function ModelManager() {
  12. this._modelList = {};
  13. }
  14. /**
  15. * 单例获取类
  16. */
  17. ModelManager.getInstance = function () {
  18. return this._instance;
  19. };
  20. /**
  21. * 获取model对象
  22. * @param {{new (): BaseModel}} model
  23. */
  24. ModelManager.prototype.getModel = function (model) {
  25. var key = cc.js.getClassName(model);
  26. return this._modelList[key];
  27. };
  28. /**
  29. * 注册数据model
  30. * @param {{new (): BaseModel}} model
  31. */
  32. ModelManager.prototype.registerModel = function (model) {
  33. var key = cc.js.getClassName(model);
  34. if (this._modelList.hasOwnProperty(key)) {
  35. console.log(key, "已经存在,不可重复注册!");
  36. }
  37. else {
  38. var m = new model();
  39. m.init();
  40. this._modelList[key] = m;
  41. }
  42. };
  43. /**
  44. * 移除注册
  45. * @param {{new (): BaseModel}} model
  46. */
  47. ModelManager.prototype.unregisterModel = function (model) {
  48. var key = cc.js.getClassName(model);
  49. if (this._modelList.hasOwnProperty(key)) {
  50. var m = this._modelList[key];
  51. m.clear();
  52. delete this._modelList[key];
  53. }
  54. else {
  55. console.warn(key, "不存在!");
  56. }
  57. };
  58. /**
  59. * 释放并移除所有model
  60. */
  61. ModelManager.prototype.removeAllModel = function () {
  62. // 释放并移除所有model
  63. for (var key in this._modelList) {
  64. var model = this._modelList[key];
  65. model.clear();
  66. delete this._modelList[key];
  67. }
  68. this._modelList = {};
  69. };
  70. /** 实例 */
  71. ModelManager._instance = new ModelManager();
  72. return ModelManager;
  73. }());
  74. exports.default = ModelManager;
  75. cc._RF.pop();