@cloudcome/utils-vue 1.11.11 → 1.12.0

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.
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const VERSION = "1.11.10";
3
+ const VERSION = "1.11.11";
4
4
  exports.VERSION = VERSION;
5
5
  //# sourceMappingURL=index.cjs.map
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- const VERSION = "1.11.10";
1
+ const VERSION = "1.11.11";
2
2
  export {
3
3
  VERSION
4
4
  };
package/dist/state.cjs ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const vue = require("vue");
4
+ function useOnceState(value, options) {
5
+ let lastValue = value;
6
+ const changed = vue.ref(false);
7
+ const { equal = Object.is } = options || {};
8
+ return {
9
+ change(newValue) {
10
+ if (equal(newValue, lastValue)) {
11
+ return;
12
+ }
13
+ if (changed.value) {
14
+ return;
15
+ }
16
+ changed.value = true;
17
+ lastValue = newValue;
18
+ },
19
+ // 这里需要使用 computed 确保返回的是原始值,而不是 reactive 包装后的对象
20
+ state: vue.computed(() => {
21
+ if (!changed.value) {
22
+ return value;
23
+ }
24
+ return lastValue;
25
+ })
26
+ };
27
+ }
28
+ exports.useOnceState = useOnceState;
29
+ //# sourceMappingURL=state.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.cjs","sources":["../src/state.ts"],"sourcesContent":["import { computed, ref } from 'vue';\n\nexport type UseOnceValueOptions<T> = {\n equal?: (a: T, b: T) => boolean;\n};\n\n/**\n * 只改变一次的值\n * @param value 初始值\n * @param options 选项\n * @returns 包含 change 方法和 value 响应式值的对象\n */\nexport function useOnceState<T>(value: T, options?: UseOnceValueOptions<T>) {\n let lastValue = value;\n const changed = ref(false);\n const { equal = Object.is } = options || {};\n\n return {\n change(newValue: T) {\n if (equal(newValue, lastValue)) {\n return;\n }\n\n if (changed.value) {\n return;\n }\n\n changed.value = true;\n lastValue = newValue;\n },\n // 这里需要使用 computed 确保返回的是原始值,而不是 reactive 包装后的对象\n state: computed(() => {\n // changed 使用响应式是为确保 computed 能够响应式更新\n if (!changed.value) {\n return value;\n }\n\n return lastValue;\n }),\n };\n}\n"],"names":["ref","computed"],"mappings":";;;AAYgB,SAAA,aAAgB,OAAU,SAAkC;AAC1E,MAAI,YAAY;AACV,QAAA,UAAUA,QAAI,KAAK;AACzB,QAAM,EAAE,QAAQ,OAAO,GAAG,IAAI,WAAW,CAAC;AAEnC,SAAA;AAAA,IACL,OAAO,UAAa;AACd,UAAA,MAAM,UAAU,SAAS,GAAG;AAC9B;AAAA,MAAA;AAGF,UAAI,QAAQ,OAAO;AACjB;AAAA,MAAA;AAGF,cAAQ,QAAQ;AACJ,kBAAA;AAAA,IACd;AAAA;AAAA,IAEA,OAAOC,aAAS,MAAM;AAEhB,UAAA,CAAC,QAAQ,OAAO;AACX,eAAA;AAAA,MAAA;AAGF,aAAA;AAAA,IACR,CAAA;AAAA,EACH;AACF;;"}
@@ -0,0 +1,13 @@
1
+ export type UseOnceValueOptions<T> = {
2
+ equal?: (a: T, b: T) => boolean;
3
+ };
4
+ /**
5
+ * 只改变一次的值
6
+ * @param value 初始值
7
+ * @param options 选项
8
+ * @returns 包含 change 方法和 value 响应式值的对象
9
+ */
10
+ export declare function useOnceState<T>(value: T, options?: UseOnceValueOptions<T>): {
11
+ change(newValue: T): void;
12
+ state: import('vue').ComputedRef<T>;
13
+ };
package/dist/state.mjs ADDED
@@ -0,0 +1,29 @@
1
+ import { ref, computed } from "vue";
2
+ function useOnceState(value, options) {
3
+ let lastValue = value;
4
+ const changed = ref(false);
5
+ const { equal = Object.is } = options || {};
6
+ return {
7
+ change(newValue) {
8
+ if (equal(newValue, lastValue)) {
9
+ return;
10
+ }
11
+ if (changed.value) {
12
+ return;
13
+ }
14
+ changed.value = true;
15
+ lastValue = newValue;
16
+ },
17
+ // 这里需要使用 computed 确保返回的是原始值,而不是 reactive 包装后的对象
18
+ state: computed(() => {
19
+ if (!changed.value) {
20
+ return value;
21
+ }
22
+ return lastValue;
23
+ })
24
+ };
25
+ }
26
+ export {
27
+ useOnceState
28
+ };
29
+ //# sourceMappingURL=state.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.mjs","sources":["../src/state.ts"],"sourcesContent":["import { computed, ref } from 'vue';\n\nexport type UseOnceValueOptions<T> = {\n equal?: (a: T, b: T) => boolean;\n};\n\n/**\n * 只改变一次的值\n * @param value 初始值\n * @param options 选项\n * @returns 包含 change 方法和 value 响应式值的对象\n */\nexport function useOnceState<T>(value: T, options?: UseOnceValueOptions<T>) {\n let lastValue = value;\n const changed = ref(false);\n const { equal = Object.is } = options || {};\n\n return {\n change(newValue: T) {\n if (equal(newValue, lastValue)) {\n return;\n }\n\n if (changed.value) {\n return;\n }\n\n changed.value = true;\n lastValue = newValue;\n },\n // 这里需要使用 computed 确保返回的是原始值,而不是 reactive 包装后的对象\n state: computed(() => {\n // changed 使用响应式是为确保 computed 能够响应式更新\n if (!changed.value) {\n return value;\n }\n\n return lastValue;\n }),\n };\n}\n"],"names":[],"mappings":";AAYgB,SAAA,aAAgB,OAAU,SAAkC;AAC1E,MAAI,YAAY;AACV,QAAA,UAAU,IAAI,KAAK;AACzB,QAAM,EAAE,QAAQ,OAAO,GAAG,IAAI,WAAW,CAAC;AAEnC,SAAA;AAAA,IACL,OAAO,UAAa;AACd,UAAA,MAAM,UAAU,SAAS,GAAG;AAC9B;AAAA,MAAA;AAGF,UAAI,QAAQ,OAAO;AACjB;AAAA,MAAA;AAGF,cAAQ,QAAQ;AACJ,kBAAA;AAAA,IACd;AAAA;AAAA,IAEA,OAAO,SAAS,MAAM;AAEhB,UAAA,CAAC,QAAQ,OAAO;AACX,eAAA;AAAA,MAAA;AAGF,aAAA;AAAA,IACR,CAAA;AAAA,EACH;AACF;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudcome/utils-vue",
3
- "version": "1.11.11",
3
+ "version": "1.12.0",
4
4
  "description": "cloudcome utils for vue",
5
5
  "engines": {
6
6
  "node": ">=22"
@@ -39,6 +39,11 @@
39
39
  "import": "./dist/shared.mjs",
40
40
  "require": "./dist/shared.cjs"
41
41
  },
42
+ "./state": {
43
+ "types": "./dist/state.d.ts",
44
+ "import": "./dist/state.mjs",
45
+ "require": "./dist/state.cjs"
46
+ },
42
47
  "./time": {
43
48
  "types": "./dist/time.d.ts",
44
49
  "import": "./dist/time.mjs",
@@ -67,6 +72,9 @@
67
72
  "shared": [
68
73
  "./dist/shared.d.ts"
69
74
  ],
75
+ "state": [
76
+ "./dist/state.d.ts"
77
+ ],
70
78
  "time": [
71
79
  "./dist/time.d.ts"
72
80
  ],