@coaction/vue 2.0.0 → 3.0.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/README.md +5 -5
- package/dist/index.js +20 -1
- package/dist/index.mjs +20 -1
- package/package.json +11 -6
package/README.md
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
# @coaction/vue
|
|
2
2
|
|
|
3
|
-

|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
 [](https://www.npmjs.com/package/@coaction/vue) 
|
|
4
|
+
|
|
5
|
+
[English documentation](https://coactionjs.github.io/coaction/en/docs/) · [中文文档](https://coactionjs.github.io/coaction/zh/docs/)
|
|
6
6
|
|
|
7
7
|
A Coaction integration tool for Vue
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Install it with pnpm:
|
|
12
12
|
|
|
13
13
|
```sh
|
|
14
|
-
|
|
14
|
+
pnpm add coaction @coaction/vue
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
## Usage
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
//#endregion
|
|
3
3
|
let coaction = require("coaction");
|
|
4
|
+
let coaction_adapter = require("coaction/adapter");
|
|
4
5
|
let vue = require("vue");
|
|
5
6
|
//#region packages/coaction-vue/src/index.ts
|
|
6
7
|
const getOwnEnumerableKeys = (value) => Reflect.ownKeys(value).filter((key) => Object.prototype.propertyIsEnumerable.call(value, key));
|
|
@@ -8,6 +9,7 @@ const isPlainObject = (value) => {
|
|
|
8
9
|
const prototype = Object.getPrototypeOf(value);
|
|
9
10
|
return prototype === Object.prototype || prototype === null;
|
|
10
11
|
};
|
|
12
|
+
const directMutationErrorMessage = "Direct state mutation is not allowed in immutable Coaction stores. Wrap mutations in set(() => { ... }).";
|
|
11
13
|
const createStateProxy = (store, version) => new Proxy({}, {
|
|
12
14
|
get(_, key) {
|
|
13
15
|
version.value;
|
|
@@ -29,6 +31,23 @@ const createStateProxy = (store, version) => new Proxy({}, {
|
|
|
29
31
|
...descriptor,
|
|
30
32
|
configurable: true
|
|
31
33
|
};
|
|
34
|
+
},
|
|
35
|
+
set(_, key, value) {
|
|
36
|
+
const state = store.getState();
|
|
37
|
+
state[key] = value;
|
|
38
|
+
return true;
|
|
39
|
+
},
|
|
40
|
+
deleteProperty(_, key) {
|
|
41
|
+
const state = store.getState();
|
|
42
|
+
if (!(key in state)) throw new TypeError(`Unknown state key '${String(key)}' cannot be deleted.`);
|
|
43
|
+
delete state[key];
|
|
44
|
+
return true;
|
|
45
|
+
},
|
|
46
|
+
defineProperty() {
|
|
47
|
+
throw new Error(directMutationErrorMessage);
|
|
48
|
+
},
|
|
49
|
+
setPrototypeOf() {
|
|
50
|
+
throw new Error(directMutationErrorMessage);
|
|
32
51
|
}
|
|
33
52
|
});
|
|
34
53
|
const createAutoSelector = (store, version) => {
|
|
@@ -91,7 +110,7 @@ const create = (createState, options) => {
|
|
|
91
110
|
};
|
|
92
111
|
const stateProxy = createStateProxy(store, version);
|
|
93
112
|
let autoSelector;
|
|
94
|
-
return (0,
|
|
113
|
+
return (0, coaction_adapter.wrapStore)(store, (selector) => {
|
|
95
114
|
if (typeof selector === "function") return (0, vue.computed)(() => {
|
|
96
115
|
version.value;
|
|
97
116
|
return selector(store.getState());
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { create as create$1
|
|
1
|
+
import { create as create$1 } from "coaction";
|
|
2
|
+
import { wrapStore } from "coaction/adapter";
|
|
2
3
|
import { computed, ref } from "vue";
|
|
3
4
|
export * from "coaction";
|
|
4
5
|
//#endregion
|
|
@@ -8,6 +9,7 @@ const isPlainObject = (value) => {
|
|
|
8
9
|
const prototype = Object.getPrototypeOf(value);
|
|
9
10
|
return prototype === Object.prototype || prototype === null;
|
|
10
11
|
};
|
|
12
|
+
const directMutationErrorMessage = "Direct state mutation is not allowed in immutable Coaction stores. Wrap mutations in set(() => { ... }).";
|
|
11
13
|
const createStateProxy = (store, version) => new Proxy({}, {
|
|
12
14
|
get(_, key) {
|
|
13
15
|
version.value;
|
|
@@ -29,6 +31,23 @@ const createStateProxy = (store, version) => new Proxy({}, {
|
|
|
29
31
|
...descriptor,
|
|
30
32
|
configurable: true
|
|
31
33
|
};
|
|
34
|
+
},
|
|
35
|
+
set(_, key, value) {
|
|
36
|
+
const state = store.getState();
|
|
37
|
+
state[key] = value;
|
|
38
|
+
return true;
|
|
39
|
+
},
|
|
40
|
+
deleteProperty(_, key) {
|
|
41
|
+
const state = store.getState();
|
|
42
|
+
if (!(key in state)) throw new TypeError(`Unknown state key '${String(key)}' cannot be deleted.`);
|
|
43
|
+
delete state[key];
|
|
44
|
+
return true;
|
|
45
|
+
},
|
|
46
|
+
defineProperty() {
|
|
47
|
+
throw new Error(directMutationErrorMessage);
|
|
48
|
+
},
|
|
49
|
+
setPrototypeOf() {
|
|
50
|
+
throw new Error(directMutationErrorMessage);
|
|
32
51
|
}
|
|
33
52
|
});
|
|
34
53
|
const createAutoSelector = (store, version) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coaction/vue",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "A Coaction integration tool for Vue",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"coaction",
|
|
@@ -29,9 +29,14 @@
|
|
|
29
29
|
"types": "dist/index.d.ts",
|
|
30
30
|
"exports": {
|
|
31
31
|
".": {
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./dist/index.d.mts",
|
|
34
|
+
"default": "./dist/index.mjs"
|
|
35
|
+
},
|
|
36
|
+
"require": {
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"default": "./dist/index.js"
|
|
39
|
+
},
|
|
35
40
|
"default": "./dist/index.mjs"
|
|
36
41
|
},
|
|
37
42
|
"./package.json": "./package.json"
|
|
@@ -43,10 +48,10 @@
|
|
|
43
48
|
"devDependencies": {
|
|
44
49
|
"@testing-library/vue": "^8.1.0",
|
|
45
50
|
"vue": "^3.5.30",
|
|
46
|
-
"coaction": "
|
|
51
|
+
"coaction": "3.0.0"
|
|
47
52
|
},
|
|
48
53
|
"peerDependencies": {
|
|
49
|
-
"coaction": "^
|
|
54
|
+
"coaction": "^3.0.0",
|
|
50
55
|
"vue": "^3.0.0"
|
|
51
56
|
},
|
|
52
57
|
"authors": [
|