RedPointMgr.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. Object.defineProperty(i, "__esModule", {value: !0}), (i.RedPointMgr = void 0);
  5. class s {
  6. constructor() {
  7. (this.types = {}), (this._observerList = {}), (this._observerGroupMap = new Map()), (this.types = s.types);
  8. }
  9. next(e, ...i) {
  10. if (this._observerList[e]) {
  11. this._observerList[e].args = i;
  12. var s = this._observerList[e].funcs.length;
  13. for (let t = 0; t < s; t++) this._observerList[e].funcs[t].apply(this._observerList[e].targets[t], i);
  14. } else this._observerList[e] = {targets: [], funcs: [], args: i};
  15. }
  16. subscribeGroup(t, e, i) {
  17. this._observerGroupMap.has(i);
  18. let s = 0,
  19. o = () => {
  20. s = 0;
  21. for (const e of t)
  22. if (this._observerList[e] && this._observerList[e].args) {
  23. const t = this._observerList[e].args[0];
  24. "number" == typeof t ? (s += t) : (s = t || s);
  25. }
  26. e.call(i, s);
  27. };
  28. for (const a of t) this.subscribe(a, o, null, !1);
  29. this._observerGroupMap.set(i, {types: t, func: o}), o.call(i, !1);
  30. }
  31. unsubscribeGroup(t) {
  32. var e = this._observerGroupMap.get(t);
  33. if (e) {
  34. this._observerGroupMap.delete(t);
  35. var i = e.types.length;
  36. for (let t = 0; t < i; t++) this.unsubscribe(e.types[t], e.func, null);
  37. }
  38. }
  39. subscribe(t, e, i, s = !0) {
  40. this._observerList[t]
  41. ? (-1 < this._observerList[t].funcs.indexOf(e) && -1 < this._observerList[t].targets.indexOf(i)) ||
  42. (this._observerList[t].funcs.push(e),
  43. this._observerList[t].targets.push(i),
  44. s &&
  45. this._observerList[t].args &&
  46. this._observerList[t].args.length &&
  47. e.apply(i, this._observerList[t].args))
  48. : (this._observerList[t] = {args: null, targets: [i], funcs: [e]});
  49. }
  50. unsubscribe(e, i, s) {
  51. if (this._observerList[e]) {
  52. var o = this._observerList[e],
  53. a = o.funcs.length;
  54. for (let t = 0; t < a; t++)
  55. if (o.targets[t] === s && o.funcs[t] === i) {
  56. this._observerList[e].funcs.splice(t, 1), this._observerList[e].targets.splice(t, 1);
  57. break;
  58. }
  59. }
  60. }
  61. }
  62. (i.RedPointMgr = s).types = {};