annil 1.7.8 → 1.8.1

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.
Files changed (69) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/api/DefineComponent/normalizeOptions/__throttleDebounce__FieldCheck.d.ts +3 -0
  3. package/dist/api/DefineComponent/normalizeOptions/__throttleDebounce__FieldCheck.js +26 -0
  4. package/dist/api/DefineComponent/normalizeOptions/__throttleDebounce__FieldCheck.js.map +1 -0
  5. package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/computedUpdater.js +4 -4
  6. package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/computedUpdater.js.map +1 -1
  7. package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/data-tracer.d.ts +1 -1
  8. package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/data-tracer.js +7 -12
  9. package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/data-tracer.js.map +1 -1
  10. package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/getPropertiesValue.d.ts +1 -1
  11. package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/getPropertiesValue.js +1 -2
  12. package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/getPropertiesValue.js.map +1 -1
  13. package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/initComputedAndGetCache.js +2 -2
  14. package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/initComputedAndGetCache.js.map +1 -1
  15. package/dist/api/DefineComponent/normalizeOptions/customEventsHandle.d.ts +1 -1
  16. package/dist/api/DefineComponent/normalizeOptions/customEventsHandle.js +17 -1
  17. package/dist/api/DefineComponent/normalizeOptions/customEventsHandle.js.map +1 -1
  18. package/dist/api/DefineComponent/normalizeOptions/index.d.ts +2 -0
  19. package/dist/api/DefineComponent/normalizeOptions/index.js +8 -1
  20. package/dist/api/DefineComponent/normalizeOptions/index.js.map +1 -1
  21. package/dist/api/DefineComponent/normalizeOptions/internalFieldProtection.js +1 -1
  22. package/dist/api/DefineComponent/normalizeOptions/internalFieldProtection.js.map +1 -1
  23. package/dist/api/DefineComponent/normalizeOptions/rootComponentOptionHandle.js +2 -1
  24. package/dist/api/DefineComponent/normalizeOptions/rootComponentOptionHandle.js.map +1 -1
  25. package/dist/api/DefineComponent/normalizeOptions/sameFuncOptionsHandle.js +2 -2
  26. package/dist/api/DefineComponent/normalizeOptions/sameFuncOptionsHandle.js.map +1 -1
  27. package/dist/api/RootComponent/CustomEvents/CustomEventConstraint.d.ts +22 -0
  28. package/dist/api/RootComponent/CustomEvents/GetCustomEventDoc.d.ts +3 -2
  29. package/dist/behaviors/BbeforeCreated.js +1 -1
  30. package/dist/behaviors/BbeforeCreated.js.map +1 -1
  31. package/dist/behaviors/BthrottleDebounce.d.ts +1 -0
  32. package/dist/behaviors/BthrottleDebounce.js +27 -0
  33. package/dist/behaviors/BthrottleDebounce.js.map +1 -0
  34. package/dist/index.d.ts +1 -0
  35. package/dist/index.js +1 -0
  36. package/dist/index.js.map +1 -1
  37. package/dist/utils/_utils.d.ts +7 -0
  38. package/dist/utils/_utils.js +8 -0
  39. package/dist/utils/_utils.js.map +1 -0
  40. package/dist/utils/debounce.d.ts +8 -0
  41. package/dist/utils/debounce.js +18 -0
  42. package/dist/utils/debounce.js.map +1 -0
  43. package/dist/utils/deepEqual.d.ts +1 -7
  44. package/dist/utils/deepEqual.js +18 -58
  45. package/dist/utils/deepEqual.js.map +1 -1
  46. package/dist/utils/throttle.d.ts +10 -0
  47. package/dist/utils/throttle.js +18 -0
  48. package/dist/utils/throttle.js.map +1 -0
  49. package/package.json +5 -8
  50. package/src/api/DefineComponent/normalizeOptions/__throttleDebounce__FieldCheck.ts +27 -0
  51. package/src/api/DefineComponent/normalizeOptions/computedWatchHandle/computedUpdater.ts +4 -5
  52. package/src/api/DefineComponent/normalizeOptions/computedWatchHandle/data-tracer.ts +7 -13
  53. package/src/api/DefineComponent/normalizeOptions/computedWatchHandle/getPropertiesValue.ts +2 -4
  54. package/src/api/DefineComponent/normalizeOptions/computedWatchHandle/initComputedAndGetCache.ts +2 -2
  55. package/src/api/DefineComponent/normalizeOptions/customEventsHandle.ts +24 -3
  56. package/src/api/DefineComponent/normalizeOptions/index.ts +11 -2
  57. package/src/api/DefineComponent/normalizeOptions/internalFieldProtection.ts +1 -1
  58. package/src/api/DefineComponent/normalizeOptions/rootComponentOptionHandle.ts +2 -1
  59. package/src/api/DefineComponent/normalizeOptions/sameFuncOptionsHandle.ts +2 -2
  60. package/src/api/RootComponent/Computed/test/error.test.ts +13 -0
  61. package/src/api/RootComponent/CustomEvents/CustomEventConstraint.ts +22 -0
  62. package/src/api/RootComponent/CustomEvents/GetCustomEventDoc.ts +4 -2
  63. package/src/behaviors/BbeforeCreated.ts +1 -1
  64. package/src/behaviors/BthrottleDebounce.ts +28 -0
  65. package/src/index.ts +2 -0
  66. package/src/utils/_utils.ts +8 -0
  67. package/src/utils/debounce.ts +19 -0
  68. package/src/utils/deepEqual.ts +19 -65
  69. package/src/utils/throttle.ts +23 -0
@@ -1,79 +1,33 @@
1
- function isSameType(a: object, b: object) {
2
- return Object.prototype.toString.call(a) === Object.prototype.toString.call(b);
1
+ type PlainObject = Record<string, unknown>;
2
+ // 非null的对象类型
3
+ function isNonNullObject(value: unknown): boolean {
4
+ return value !== null && typeof value === "object";
3
5
  }
4
6
 
5
- // 定义一个辅助函数,用于判断两个对象的属性数量是否相同
6
- function isSameSize(a: object, b: object) {
7
- return Object.keys(a).length === Object.keys(b).length;
8
- }
9
-
10
- // 定义一个辅助函数,用于判断两个函数的代码是否相同
11
- // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
12
- function isSameCode(a: Function, b: Function) {
13
- // 去除空格比较函数字符串
14
- return a.toString().split(" ").join("") === b.toString().split(" ").join("");
15
- }
16
-
17
- // 定义一个辅助函数,用于判断两个日期的时间戳是否相同
18
- function isSameTime(a: Date, b: Date) {
19
- return a.getTime() === b.getTime();
20
- }
21
-
22
- // 定义一个辅助函数,用于判断两个正则表达式的模式和标志是否相同
23
- function isSamePattern(a: RegExp, b: RegExp) {
24
- return a.source === b.source && a.flags === b.flags;
25
- }
26
-
27
- /**
28
- * 深度判断两个值是否相等,有一个值为非对象类型即使用Object.is判断。
29
- * 不支持原型上的属性
30
- * 两个函数使用toString()比较
31
- * 支持Date,RegExp
32
- */
33
- export function deepEqual(a: unknown, b: unknown) {
34
- // 如果两个值是原始类型或null,直接用Object.is比较
35
- if (a === null || b === null || typeof a !== "object" || typeof b !== "object") {
36
- if (typeof a !== "function" || typeof b !== "function") {
37
- return Object.is(a, b);
38
- }
7
+ export function deepEqual(value1: unknown, value2: unknown): boolean {
8
+ // 2个非对象类型相等或同引用对象的情况。
9
+ if (Object.is(value1, value2)) {
10
+ return true;
39
11
  }
40
- // 如果两个值是对象类型,先判断它们的类型、构造函数和属性数量是否相同
41
- if (!isSameType(a, b) || a.constructor !== b.constructor || !isSameSize(a, b)) {
12
+ // 有一个不是非空对象,返回false。
13
+ if (!isNonNullObject(value1) || !isNonNullObject(value2)) {
42
14
  return false;
43
15
  }
16
+ // 到此,2个都是对象类型。
17
+ const _value1 = value1 as PlainObject;
18
+ const _value2 = value2 as PlainObject;
19
+ const value1Keys = Object.keys(_value1);
20
+ const value2Keys = Object.keys(_value2);
44
21
 
45
- // 如果两个值是函数类型,再判断它们的代码是否相同
46
- if (typeof a === "function") {
47
- // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
48
- return isSameCode(a, b as Function);
49
- }
50
-
51
- // 如果两个值是日期类型,再判断它们的时间戳是否相同
52
- if (a instanceof Date) {
53
- return isSameTime(a, b as Date);
54
- }
55
-
56
- // // 如果两个值是正则表达式类型,再判断它们的模式和标志是否相同
57
- if (a instanceof RegExp) {
58
- return isSamePattern(a, b as RegExp);
22
+ if (value1Keys.length !== value2Keys.length) {
23
+ return false;
59
24
  }
60
25
 
61
- // 对于其他对象类型,递归地比较它们的每个属性和值是否深度相等
62
- const keysA = Object.keys(a);
63
-
64
- const keysB = Object.keys(b);
65
-
66
- for (const key of keysA) {
67
- if (keysB.includes(key)) {
68
- // @ts-ignore
69
- if (!deepEqual(a[key], b[key])) {
70
- return false;
71
- }
72
- } else {
26
+ for (const key of value1Keys) {
27
+ if (!value2Keys.includes(key) || !deepEqual(_value1[key], _value2[key])) {
73
28
  return false;
74
29
  }
75
30
  }
76
31
 
77
- // 如果以上的条件都满足,说明两个值是深度相等的
78
32
  return true;
79
33
  }
@@ -0,0 +1,23 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ type Callback = (...args: any[]) => any;
3
+
4
+ /**
5
+ * 节流函数
6
+ * 规定时间内只触发第一次 例如点击按钮
7
+ * @param callback 回调函数
8
+ * @param interval 单位毫秒
9
+ * @returns
10
+ */
11
+ export function throttle<F extends Callback>(callback: F, interval = 200): (...args: Parameters<F>) => void {
12
+ let lastCall = 0;
13
+
14
+ return function(...args: Parameters<F>) {
15
+ const now = Date.now();
16
+
17
+ if (now - lastCall >= interval) {
18
+ lastCall = now;
19
+
20
+ callback(...args);
21
+ }
22
+ };
23
+ }