light-h5-core-lib 2.9.0 → 2.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BeizerUtil = void 0;
4
4
  /**
5
- * 贝塞尔曲线运动
5
+ * 贝塞尔曲线运动工具<b style="color:red">支持多点</b>
6
6
  * @author Aonaufly
7
7
  */
8
8
  var BeizerUtil = /** @class */ (function () {
@@ -23,7 +23,7 @@ var DateUtil = /** @class */ (function () {
23
23
  return Math.floor(DateUtil.getTargetTimeStamp(date) / 1000);
24
24
  };
25
25
  /**
26
- * 格式化时间(时,分,秒)
26
+ * 格式化时间(时,分,秒)<b style="color:red">使用 separator分割</b>
27
27
  * @param s 秒
28
28
  * @param separator 分隔符(default: ":")
29
29
  * @param isSingle0 是否补0(default:true)
@@ -63,7 +63,7 @@ var DateUtil = /** @class */ (function () {
63
63
  return result;
64
64
  };
65
65
  /**
66
- * 获取下一天的时间(凌晨)秒 存在1ms误差可以忽略不计
66
+ * 获取下一天的时间(凌晨)秒 存在1ms误差可以忽略不计<b style="color:red">当天时间24:00</b>
67
67
  * @param nowSecond 现在的时间秒 ( 服务器的时间(一般))
68
68
  * @return 下一天的时间Second
69
69
  * */
@@ -71,7 +71,7 @@ var DateUtil = /** @class */ (function () {
71
71
  return DateUtil.getTodayAppointTimeStamp(nowSecond, 23, 59, 59, 999);
72
72
  };
73
73
  /**
74
- * 获取今日指定的时间秒, 例如今日20:00
74
+ * 获取今日指定的时间(秒), 例如今日20:00
75
75
  * @param nowSecond 现在的时间秒 ( 服务器的时间(一般))
76
76
  * @param hour 指定的小时数 0~23
77
77
  * @param minute 指定的分钟数 0~59
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "light-h5-core-lib",
3
- "version": "2.9.0",
3
+ "version": "2.9.2",
4
4
  "description": "light core lib",
5
5
  "main": "./LightCore.js",
6
6
  "types": "./type/index.d.ts",
package/pool/PoolObj.js CHANGED
@@ -7,24 +7,96 @@ exports.PoolObj = void 0;
7
7
  */
8
8
  var PoolObj = /** @class */ (function () {
9
9
  /**
10
- * @param cap 容量(容积)
10
+ * @param cap 容量(容积) <b style="color:red">小于等于0:无限容量,慎用</b>
11
+ * @param initCreateNum 初始化创建数量 <b style="color:red">(createCallback != null 有效)</b>
12
+ * @param createCallback Item创建函数
13
+ * @param clearCallback Item清理函数
14
+ * @param destroyCallback Item销毁函数
11
15
  */
12
- function PoolObj(cap) {
16
+ function PoolObj(cap, initCreateNum, createCallback, clearCallback, destroyCallback) {
13
17
  if (cap === void 0) { cap = 5; }
14
- this._cap = cap;
18
+ if (initCreateNum === void 0) { initCreateNum = 0; }
19
+ if (createCallback === void 0) { createCallback = null; }
20
+ if (clearCallback === void 0) { clearCallback = null; }
21
+ if (destroyCallback === void 0) { destroyCallback = null; }
22
+ this._cap = cap == null ? 5 : cap;
23
+ this._createCallback = createCallback;
24
+ this._clearCallback = clearCallback;
25
+ this._destroyCallback = destroyCallback;
15
26
  this._pool = [];
27
+ this.initCreate(initCreateNum == null ? 0 : initCreateNum);
16
28
  }
29
+ /**
30
+ * 初始化一些数量的item
31
+ */
32
+ PoolObj.prototype.initCreate = function (initCreateNum) {
33
+ if (initCreateNum <= 0)
34
+ return;
35
+ if (!this._createCallback)
36
+ return;
37
+ var maxNum = this._cap > 0 ? Math.min(this._cap, initCreateNum) : initCreateNum;
38
+ for (var i = 0; i < maxNum; i++) {
39
+ this._pool.push(this._createCallback());
40
+ }
41
+ };
42
+ /**
43
+ * 放入到对象池
44
+ * @return 放入到对象池是否成功
45
+ */
17
46
  PoolObj.prototype.put = function (obj) {
18
- if (!obj || this._pool.length >= this._cap)
47
+ if (!obj)
48
+ return false;
49
+ if (this._cap > 0 && this._pool.length >= this._cap) {
50
+ this._destroyCallback && this._destroyCallback(obj);
19
51
  return false;
52
+ }
53
+ this._clearCallback && this._clearCallback(obj);
20
54
  this._pool.push(obj);
21
55
  return true;
22
56
  };
57
+ /**
58
+ * 获得一个Item<br>
59
+ * <b style="color:green">如果size==0,则自动使用createCallback创建</b><br>
60
+ * <b style="color:red">⚠️如果size==0 && createCallback==null,则返回null</b>
61
+ */
23
62
  PoolObj.prototype.one = function () {
24
- if (this._pool.length == 0)
25
- return null;
63
+ if (this._pool.length == 0) {
64
+ if (!this._createCallback)
65
+ return null;
66
+ return this._createCallback();
67
+ }
26
68
  return this._pool.shift();
27
69
  };
70
+ Object.defineProperty(PoolObj.prototype, "isExistCreateCallback", {
71
+ /**
72
+ * 是否存在Item创建方法
73
+ */
74
+ get: function () {
75
+ return this._createCallback != null;
76
+ },
77
+ enumerable: false,
78
+ configurable: true
79
+ });
80
+ Object.defineProperty(PoolObj.prototype, "isExistClearCallback", {
81
+ /**
82
+ * 是否存在Item的清理函数
83
+ */
84
+ get: function () {
85
+ return this._clearCallback != null;
86
+ },
87
+ enumerable: false,
88
+ configurable: true
89
+ });
90
+ Object.defineProperty(PoolObj.prototype, "isExistDestroyCallback", {
91
+ /**
92
+ * 是否存在Item的销毁函数
93
+ */
94
+ get: function () {
95
+ return this._destroyCallback != null;
96
+ },
97
+ enumerable: false,
98
+ configurable: true
99
+ });
28
100
  Object.defineProperty(PoolObj.prototype, "cap", {
29
101
  /**
30
102
  * 获取容量(容积)
@@ -58,13 +130,10 @@ var PoolObj = /** @class */ (function () {
58
130
  var obj;
59
131
  for (var i = 0, j = this._pool.length; i < j; i++) {
60
132
  obj = this._pool[i];
61
- if (obj.destroy) {
62
- obj.destroy();
63
- }
64
- else if (obj.onDestroy) {
65
- obj.onDestroy();
133
+ if (obj) {
134
+ this._destroyCallback && this._destroyCallback(obj);
135
+ obj = null;
66
136
  }
67
- obj = null;
68
137
  }
69
138
  this._pool.length = 0;
70
139
  };
@@ -72,6 +141,9 @@ var PoolObj = /** @class */ (function () {
72
141
  if (!isCleared) {
73
142
  this.clear();
74
143
  }
144
+ this._createCallback = null;
145
+ this._clearCallback = null;
146
+ this._destroyCallback = null;
75
147
  this._pool && (this._pool = null);
76
148
  };
77
149
  return PoolObj;
package/type/index.d.ts CHANGED
@@ -13,12 +13,44 @@ export interface IClear extends IDestroy {
13
13
  export declare class PoolObj<T> implements IClear {
14
14
  private _pool;
15
15
  private _cap;
16
+ private _createCallback;
17
+ private _clearCallback;
18
+ private _destroyCallback;
16
19
  /**
17
- * @param cap 容量(容积)
20
+ * @param cap 容量(容积) <b style="color:red">小于等于0:无限容量,慎用</b>
21
+ * @param initCreateNum 初始化创建数量 <b style="color:red">(createCallback != null 有效)</b>
22
+ * @param createCallback Item创建函数
23
+ * @param clearCallback Item清理函数
24
+ * @param destroyCallback Item销毁函数
25
+ */
26
+ constructor(cap?: number, initCreateNum?: number, createCallback?: () => T, clearCallback?: (item: T) => void, destroyCallback?: (item: T) => void);
27
+ /**
28
+ * 初始化一些数量的item
29
+ */
30
+ private initCreate;
31
+ /**
32
+ * 放入到对象池
33
+ * @return 放入到对象池是否成功
18
34
  */
19
- constructor(cap?: number);
20
35
  put(obj: T): boolean;
36
+ /**
37
+ * 获得一个Item<br>
38
+ * <b style="color:green">如果size==0,则自动使用createCallback创建</b><br>
39
+ * <b style="color:red">⚠️如果size==0 && createCallback==null,则返回null</b>
40
+ */
21
41
  one(): T;
42
+ /**
43
+ * 是否存在Item创建方法
44
+ */
45
+ get isExistCreateCallback(): boolean;
46
+ /**
47
+ * 是否存在Item的清理函数
48
+ */
49
+ get isExistClearCallback(): boolean;
50
+ /**
51
+ * 是否存在Item的销毁函数
52
+ */
53
+ get isExistDestroyCallback(): boolean;
22
54
  /**
23
55
  * 获取容量(容积)
24
56
  */
@@ -81,7 +113,7 @@ export declare class DateUtil {
81
113
  */
82
114
  static getTargetSeconds(date: string): number;
83
115
  /**
84
- * 格式化时间(时,分,秒)
116
+ * 格式化时间(时,分,秒)<b style="color:red">使用 separator分割</b>
85
117
  * @param s 秒
86
118
  * @param separator 分隔符(default: ":")
87
119
  * @param isSingle0 是否补0(default:true)
@@ -96,13 +128,13 @@ export declare class DateUtil {
96
128
  */
97
129
  static format_MS(s: number, separator?: string, isSingle0?: boolean): string;
98
130
  /**
99
- * 获取下一天的时间(凌晨)秒 存在1ms误差可以忽略不计
131
+ * 获取下一天的时间(凌晨)秒 存在1ms误差可以忽略不计<b style="color:red">当天时间24:00</b>
100
132
  * @param nowSecond 现在的时间秒 ( 服务器的时间(一般))
101
133
  * @return 下一天的时间Second
102
134
  * */
103
135
  static getNextDayTimeStamp(nowSecond: number): number;
104
136
  /**
105
- * 获取今日指定的时间秒, 例如今日20:00
137
+ * 获取今日指定的时间(秒), 例如今日20:00
106
138
  * @param nowSecond 现在的时间秒 ( 服务器的时间(一般))
107
139
  * @param hour 指定的小时数 0~23
108
140
  * @param minute 指定的分钟数 0~59
@@ -229,7 +261,7 @@ export declare class UniqueIDUtil {
229
261
  static getCompositeKey(key: string | number, uniqueId: string): string;
230
262
  }
231
263
  /**
232
- * 贝塞尔曲线运动
264
+ * 贝塞尔曲线运动工具<b style="color:red">支持多点</b>
233
265
  * @author Aonaufly
234
266
  */
235
267
  export declare class BeizerUtil {