@coaction/vue 2.0.0 → 2.1.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 CHANGED
@@ -1,17 +1,15 @@
1
1
  # @coaction/vue
2
2
 
3
- ![Node CI](https://github.com/coactionjs/coaction/workflows/Node%20CI/badge.svg)
4
- [![npm](https://img.shields.io/npm/v/@coaction/vue.svg)](https://www.npmjs.com/package/@coaction/vue)
5
- ![license](https://img.shields.io/npm/l/@coaction/vue)
3
+ ![Node CI](https://github.com/coactionjs/coaction/workflows/Node%20CI/badge.svg) [![npm](https://img.shields.io/npm/v/@coaction/vue.svg)](https://www.npmjs.com/package/@coaction/vue) ![license](https://img.shields.io/npm/l/@coaction/vue)
6
4
 
7
5
  A Coaction integration tool for Vue
8
6
 
9
7
  ## Installation
10
8
 
11
- You can install it via npm, yarn or pnpm.
9
+ Install it with pnpm:
12
10
 
13
11
  ```sh
14
- npm install coaction @coaction/vue
12
+ pnpm add coaction @coaction/vue
15
13
  ```
16
14
 
17
15
  ## Usage
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ const isPlainObject = (value) => {
8
8
  const prototype = Object.getPrototypeOf(value);
9
9
  return prototype === Object.prototype || prototype === null;
10
10
  };
11
+ const directMutationErrorMessage = "Direct state mutation is not allowed in immutable Coaction stores. Wrap mutations in set(() => { ... }).";
11
12
  const createStateProxy = (store, version) => new Proxy({}, {
12
13
  get(_, key) {
13
14
  version.value;
@@ -29,6 +30,23 @@ const createStateProxy = (store, version) => new Proxy({}, {
29
30
  ...descriptor,
30
31
  configurable: true
31
32
  };
33
+ },
34
+ set(_, key, value) {
35
+ const state = store.getState();
36
+ state[key] = value;
37
+ return true;
38
+ },
39
+ deleteProperty(_, key) {
40
+ const state = store.getState();
41
+ if (!(key in state)) throw new TypeError(`Unknown state key '${String(key)}' cannot be deleted.`);
42
+ delete state[key];
43
+ return true;
44
+ },
45
+ defineProperty() {
46
+ throw new Error(directMutationErrorMessage);
47
+ },
48
+ setPrototypeOf() {
49
+ throw new Error(directMutationErrorMessage);
32
50
  }
33
51
  });
34
52
  const createAutoSelector = (store, version) => {
package/dist/index.mjs CHANGED
@@ -8,6 +8,7 @@ const isPlainObject = (value) => {
8
8
  const prototype = Object.getPrototypeOf(value);
9
9
  return prototype === Object.prototype || prototype === null;
10
10
  };
11
+ const directMutationErrorMessage = "Direct state mutation is not allowed in immutable Coaction stores. Wrap mutations in set(() => { ... }).";
11
12
  const createStateProxy = (store, version) => new Proxy({}, {
12
13
  get(_, key) {
13
14
  version.value;
@@ -29,6 +30,23 @@ const createStateProxy = (store, version) => new Proxy({}, {
29
30
  ...descriptor,
30
31
  configurable: true
31
32
  };
33
+ },
34
+ set(_, key, value) {
35
+ const state = store.getState();
36
+ state[key] = value;
37
+ return true;
38
+ },
39
+ deleteProperty(_, key) {
40
+ const state = store.getState();
41
+ if (!(key in state)) throw new TypeError(`Unknown state key '${String(key)}' cannot be deleted.`);
42
+ delete state[key];
43
+ return true;
44
+ },
45
+ defineProperty() {
46
+ throw new Error(directMutationErrorMessage);
47
+ },
48
+ setPrototypeOf() {
49
+ throw new Error(directMutationErrorMessage);
32
50
  }
33
51
  });
34
52
  const createAutoSelector = (store, version) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coaction/vue",
3
- "version": "2.0.0",
3
+ "version": "2.1.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
- "types": "./dist/index.d.ts",
33
- "import": "./dist/index.mjs",
34
- "require": "./dist/index.js",
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": "2.0.0"
51
+ "coaction": "2.1.0"
47
52
  },
48
53
  "peerDependencies": {
49
- "coaction": "^2.0.0",
54
+ "coaction": ">=2.1.0 <3",
50
55
  "vue": "^3.0.0"
51
56
  },
52
57
  "authors": [