@coaction/valtio 1.5.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 +10 -6
- package/dist/index.d.mts +11 -5
- package/dist/index.d.ts +11 -5
- package/dist/index.js +128 -97
- package/dist/index.mjs +118 -94
- package/package.json +42 -48
package/README.md
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
# @coaction/valtio
|
|
2
2
|
|
|
3
|
-
](https://www.npmjs.com/package/@coaction/valtio)
|
|
5
|
-

|
|
3
|
+
 [](https://www.npmjs.com/package/@coaction/valtio) 
|
|
6
4
|
|
|
7
5
|
A Coaction integration tool for Valtio.
|
|
8
6
|
|
|
9
7
|
## Installation
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
Install it with pnpm:
|
|
12
10
|
|
|
13
11
|
```sh
|
|
14
|
-
|
|
12
|
+
pnpm add coaction @coaction/valtio valtio
|
|
15
13
|
```
|
|
16
14
|
|
|
17
15
|
## Usage
|
|
@@ -37,7 +35,13 @@ store.getState().increment();
|
|
|
37
35
|
|
|
38
36
|
- `@coaction/valtio` only supports binding a whole Valtio store.
|
|
39
37
|
- Coaction `Slices` mode is not supported in this adapter.
|
|
38
|
+
- Shared main/client mode is supported for Coaction method execution; direct
|
|
39
|
+
writes to mirrored schema fields on the client-side Valtio proxy are restored
|
|
40
|
+
to the authoritative snapshot.
|
|
41
|
+
- Unknown root properties written directly to the Valtio proxy are ignored by
|
|
42
|
+
Coaction's fixed schema. They are not promoted into Coaction raw/public state,
|
|
43
|
+
and this adapter does not guarantee pruning them from the Valtio proxy.
|
|
40
44
|
|
|
41
45
|
## Documentation
|
|
42
46
|
|
|
43
|
-
You can find the documentation [here](https://github.com/
|
|
47
|
+
You can find the documentation [here](https://github.com/coactionjs/coaction).
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
1
|
+
import { proxy } from "valtio/vanilla";
|
|
2
|
+
export * from "valtio/vanilla";
|
|
3
3
|
|
|
4
|
+
//#region \0rolldown/runtime.js
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region packages/coaction-valtio/src/index.d.ts
|
|
4
7
|
interface BindValtio {
|
|
5
|
-
|
|
8
|
+
<T extends object>(target: T): T;
|
|
6
9
|
}
|
|
7
10
|
/**
|
|
8
11
|
* Bind a store to Valtio.
|
|
@@ -12,5 +15,8 @@ declare const bindValtio: BindValtio;
|
|
|
12
15
|
* Adapt a Valtio store type to state type.
|
|
13
16
|
*/
|
|
14
17
|
declare const adapt: <T extends object>(store: T) => T;
|
|
15
|
-
|
|
16
|
-
export { adapt, bindValtio };
|
|
18
|
+
declare namespace index_d_exports {
|
|
19
|
+
export { adapt, bindValtio, proxy };
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { adapt, bindValtio, proxy };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
1
|
+
import { proxy } from "valtio/vanilla";
|
|
2
|
+
export * from "valtio/vanilla";
|
|
3
3
|
|
|
4
|
+
//#region \0rolldown/runtime.js
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region packages/coaction-valtio/src/index.d.ts
|
|
4
7
|
interface BindValtio {
|
|
5
|
-
|
|
8
|
+
<T extends object>(target: T): T;
|
|
6
9
|
}
|
|
7
10
|
/**
|
|
8
11
|
* Bind a store to Valtio.
|
|
@@ -12,5 +15,8 @@ declare const bindValtio: BindValtio;
|
|
|
12
15
|
* Adapt a Valtio store type to state type.
|
|
13
16
|
*/
|
|
14
17
|
declare const adapt: <T extends object>(store: T) => T;
|
|
15
|
-
|
|
16
|
-
export { adapt, bindValtio };
|
|
18
|
+
declare namespace index_d_exports {
|
|
19
|
+
export { adapt, bindValtio, proxy };
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { adapt, bindValtio, proxy };
|
package/dist/index.js
CHANGED
|
@@ -1,100 +1,131 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#endregion
|
|
3
|
+
let coaction = require("coaction");
|
|
4
|
+
let valtio_vanilla = require("valtio/vanilla");
|
|
5
|
+
//#region packages/coaction-valtio/src/index.ts
|
|
6
|
+
const instancesMap = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
const handleStore = (store, rawState, state, internal) => {
|
|
8
|
+
if (!internal.toMutableRaw) {
|
|
9
|
+
internal.toMutableRaw = (key) => instancesMap.get(key);
|
|
10
|
+
const getMutableState = () => internal.toMutableRaw?.(rawState) ?? rawState;
|
|
11
|
+
let isApplyingCoactionState = false;
|
|
12
|
+
let lastSnapshot;
|
|
13
|
+
const restoreClientState = (snapshot) => {
|
|
14
|
+
isApplyingCoactionState = true;
|
|
15
|
+
try {
|
|
16
|
+
(0, coaction.replaceMutableAdapterState)(internal.rootState ?? rawState, getMutableState(), store.getState(), snapshot);
|
|
17
|
+
} finally {
|
|
18
|
+
lastSnapshot = (0, coaction.snapshotMutableAdapterPureState)(store);
|
|
19
|
+
isApplyingCoactionState = false;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const syncSharedExternalChange = () => {
|
|
23
|
+
const currentSnapshot = (0, coaction.snapshotMutableAdapterPureState)(store);
|
|
24
|
+
if (isApplyingCoactionState) {
|
|
25
|
+
lastSnapshot = currentSnapshot;
|
|
26
|
+
return "handled";
|
|
27
|
+
}
|
|
28
|
+
if (store.share === "client" && lastSnapshot) {
|
|
29
|
+
if (!(0, coaction.isEqualMutableAdapterSnapshot)(currentSnapshot, lastSnapshot)) restoreClientState(lastSnapshot);
|
|
30
|
+
return "ignored";
|
|
31
|
+
}
|
|
32
|
+
if (store.share === "main" && lastSnapshot) {
|
|
33
|
+
const rootState = internal.rootState;
|
|
34
|
+
internal.rootState = lastSnapshot;
|
|
35
|
+
try {
|
|
36
|
+
(0, coaction.replaceExternalStoreState)(store, internal, currentSnapshot, { syncImmutable: false });
|
|
37
|
+
} finally {
|
|
38
|
+
internal.rootState = rootState;
|
|
39
|
+
}
|
|
40
|
+
lastSnapshot = currentSnapshot;
|
|
41
|
+
return "handled";
|
|
42
|
+
}
|
|
43
|
+
lastSnapshot = currentSnapshot;
|
|
44
|
+
return "external";
|
|
45
|
+
};
|
|
46
|
+
store._destroyers = /* @__PURE__ */ new Set();
|
|
47
|
+
store._listeners = /* @__PURE__ */ new Set();
|
|
48
|
+
let unsubscribeExternal;
|
|
49
|
+
const cancelReadySubscription = (0, coaction.onStoreReady)(store, () => {
|
|
50
|
+
(0, coaction.replaceMutableAdapterState)(internal.rootState ?? rawState, getMutableState(), store.getState(), (0, coaction.sanitizeInitialStateValue)((0, coaction.snapshotMutableAdapterPureState)(store)));
|
|
51
|
+
lastSnapshot = (0, coaction.snapshotMutableAdapterPureState)(store);
|
|
52
|
+
unsubscribeExternal = (0, valtio_vanilla.subscribe)(getMutableState(), () => {
|
|
53
|
+
const change = syncSharedExternalChange();
|
|
54
|
+
if (change === "ignored") return;
|
|
55
|
+
if (change === "external") internal.notifyStateChange?.();
|
|
56
|
+
store._listeners?.forEach((listener) => listener());
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
Object.assign(store, { subscribe: (listener) => {
|
|
60
|
+
internal.assertAlive?.("subscribe");
|
|
61
|
+
store._listeners.add(listener);
|
|
62
|
+
return () => {
|
|
63
|
+
store._listeners?.delete(listener);
|
|
64
|
+
};
|
|
65
|
+
} });
|
|
66
|
+
const baseDestroy = store.destroy;
|
|
67
|
+
let destroyed = false;
|
|
68
|
+
store.destroy = () => {
|
|
69
|
+
if (destroyed) return;
|
|
70
|
+
destroyed = true;
|
|
71
|
+
cancelReadySubscription();
|
|
72
|
+
unsubscribeExternal?.();
|
|
73
|
+
unsubscribeExternal = void 0;
|
|
74
|
+
store._listeners?.clear();
|
|
75
|
+
store._listeners = void 0;
|
|
76
|
+
store._destroyers?.forEach((destroy) => destroy());
|
|
77
|
+
store._destroyers?.clear();
|
|
78
|
+
store._destroyers = void 0;
|
|
79
|
+
baseDestroy();
|
|
80
|
+
};
|
|
81
|
+
store.apply = (state = store.getPureState(), patches) => {
|
|
82
|
+
internal.assertAlive?.("apply");
|
|
83
|
+
isApplyingCoactionState = true;
|
|
84
|
+
try {
|
|
85
|
+
if (!patches) {
|
|
86
|
+
(0, coaction.replaceMutableAdapterState)(internal.rootState ?? rawState, getMutableState(), store.getState(), state);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
(0, coaction.applyMutableAdapterPatches)(state, patches, internal.rootState ?? rawState, getMutableState(), store.getState());
|
|
90
|
+
} finally {
|
|
91
|
+
lastSnapshot = (0, coaction.snapshotMutableAdapterPureState)(store);
|
|
92
|
+
isApplyingCoactionState = false;
|
|
93
|
+
internal.notifyStateChange?.();
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
9
97
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(index_exports);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var src_exports = {};
|
|
32
|
-
__export(src_exports, {
|
|
33
|
-
adapt: () => adapt,
|
|
34
|
-
bindValtio: () => bindValtio,
|
|
35
|
-
proxy: () => import_vanilla.proxy
|
|
36
|
-
});
|
|
37
|
-
var import_mutability = require("mutability");
|
|
38
|
-
var import_coaction = require("coaction");
|
|
39
|
-
var import_vanilla = require("valtio/vanilla");
|
|
40
|
-
__reExport(src_exports, require("valtio/vanilla"));
|
|
41
|
-
var instancesMap = /* @__PURE__ */ new WeakMap();
|
|
42
|
-
var handleStore = (store, rawState, state, internal) => {
|
|
43
|
-
if (!internal.toMutableRaw) {
|
|
44
|
-
internal.toMutableRaw = (key) => instancesMap.get(key);
|
|
45
|
-
const getMutableState = () => internal.toMutableRaw?.(rawState) ?? rawState;
|
|
46
|
-
store._destroyers = /* @__PURE__ */ new Set();
|
|
47
|
-
Object.assign(store, {
|
|
48
|
-
subscribe: (listener) => {
|
|
49
|
-
const unsubscribe = (0, import_vanilla.subscribe)(getMutableState(), listener);
|
|
50
|
-
store._destroyers.add(unsubscribe);
|
|
51
|
-
return () => {
|
|
52
|
-
unsubscribe();
|
|
53
|
-
store._destroyers?.delete(unsubscribe);
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
const baseDestroy = store.destroy;
|
|
58
|
-
store.destroy = () => {
|
|
59
|
-
store._destroyers?.forEach((destroy) => destroy());
|
|
60
|
-
store._destroyers?.clear();
|
|
61
|
-
store._destroyers = void 0;
|
|
62
|
-
baseDestroy();
|
|
63
|
-
};
|
|
64
|
-
store.apply = (state2 = store.getState(), patches) => {
|
|
65
|
-
if (!patches) {
|
|
66
|
-
Object.assign(store.getState(), state2);
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
(0, import_mutability.apply)(state2, patches);
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
var bindValtio = (0, import_coaction.createBinder)({
|
|
74
|
-
handleStore,
|
|
75
|
-
handleState: (options) => {
|
|
76
|
-
const descriptors = Object.getOwnPropertyDescriptors(options);
|
|
77
|
-
const copyState = Object.defineProperties(
|
|
78
|
-
{},
|
|
79
|
-
descriptors
|
|
80
|
-
);
|
|
81
|
-
const rawState = Object.defineProperties({}, descriptors);
|
|
82
|
-
return {
|
|
83
|
-
copyState,
|
|
84
|
-
bind: (state) => {
|
|
85
|
-
instancesMap.set(rawState, state);
|
|
86
|
-
return rawState;
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
}
|
|
98
|
+
/**
|
|
99
|
+
* Bind a store to Valtio.
|
|
100
|
+
*/
|
|
101
|
+
const bindValtio = (0, coaction.createBinder)({
|
|
102
|
+
handleStore,
|
|
103
|
+
handleState: (options) => {
|
|
104
|
+
const descriptors = Object.getOwnPropertyDescriptors(options);
|
|
105
|
+
const copyState = Object.defineProperties({}, descriptors);
|
|
106
|
+
const rawState = Object.defineProperties({}, descriptors);
|
|
107
|
+
return {
|
|
108
|
+
copyState,
|
|
109
|
+
bind: (state) => {
|
|
110
|
+
instancesMap.set(rawState, state);
|
|
111
|
+
return rawState;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
90
115
|
});
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
116
|
+
/**
|
|
117
|
+
* Adapt a Valtio store type to state type.
|
|
118
|
+
*/
|
|
119
|
+
const adapt = (store) => store;
|
|
120
|
+
//#endregion
|
|
121
|
+
exports.adapt = adapt;
|
|
122
|
+
exports.bindValtio = bindValtio;
|
|
123
|
+
exports.proxy = valtio_vanilla.proxy;
|
|
124
|
+
Object.keys(valtio_vanilla).forEach(function(k) {
|
|
125
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
126
|
+
enumerable: true,
|
|
127
|
+
get: function() {
|
|
128
|
+
return valtio_vanilla[k];
|
|
129
|
+
}
|
|
130
|
+
});
|
|
100
131
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,97 +1,121 @@
|
|
|
1
|
-
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
|
-
|
|
19
|
-
// index.ts
|
|
20
|
-
var index_exports = {};
|
|
21
|
-
__export(index_exports, {
|
|
22
|
-
adapt: () => adapt,
|
|
23
|
-
bindValtio: () => bindValtio,
|
|
24
|
-
proxy: () => proxy
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
// src/index.ts
|
|
28
|
-
var src_exports = {};
|
|
29
|
-
__export(src_exports, {
|
|
30
|
-
adapt: () => adapt,
|
|
31
|
-
bindValtio: () => bindValtio,
|
|
32
|
-
proxy: () => proxy
|
|
33
|
-
});
|
|
34
|
-
__reExport(src_exports, vanilla_star);
|
|
35
|
-
import { apply } from "mutability";
|
|
36
|
-
import { createBinder } from "coaction";
|
|
1
|
+
import { applyMutableAdapterPatches, createBinder, isEqualMutableAdapterSnapshot, onStoreReady, replaceExternalStoreState, replaceMutableAdapterState, sanitizeInitialStateValue, snapshotMutableAdapterPureState } from "coaction";
|
|
37
2
|
import { proxy, subscribe } from "valtio/vanilla";
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
3
|
+
export * from "valtio/vanilla";
|
|
4
|
+
//#endregion
|
|
5
|
+
//#region packages/coaction-valtio/src/index.ts
|
|
6
|
+
const instancesMap = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
const handleStore = (store, rawState, state, internal) => {
|
|
8
|
+
if (!internal.toMutableRaw) {
|
|
9
|
+
internal.toMutableRaw = (key) => instancesMap.get(key);
|
|
10
|
+
const getMutableState = () => internal.toMutableRaw?.(rawState) ?? rawState;
|
|
11
|
+
let isApplyingCoactionState = false;
|
|
12
|
+
let lastSnapshot;
|
|
13
|
+
const restoreClientState = (snapshot) => {
|
|
14
|
+
isApplyingCoactionState = true;
|
|
15
|
+
try {
|
|
16
|
+
replaceMutableAdapterState(internal.rootState ?? rawState, getMutableState(), store.getState(), snapshot);
|
|
17
|
+
} finally {
|
|
18
|
+
lastSnapshot = snapshotMutableAdapterPureState(store);
|
|
19
|
+
isApplyingCoactionState = false;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const syncSharedExternalChange = () => {
|
|
23
|
+
const currentSnapshot = snapshotMutableAdapterPureState(store);
|
|
24
|
+
if (isApplyingCoactionState) {
|
|
25
|
+
lastSnapshot = currentSnapshot;
|
|
26
|
+
return "handled";
|
|
27
|
+
}
|
|
28
|
+
if (store.share === "client" && lastSnapshot) {
|
|
29
|
+
if (!isEqualMutableAdapterSnapshot(currentSnapshot, lastSnapshot)) restoreClientState(lastSnapshot);
|
|
30
|
+
return "ignored";
|
|
31
|
+
}
|
|
32
|
+
if (store.share === "main" && lastSnapshot) {
|
|
33
|
+
const rootState = internal.rootState;
|
|
34
|
+
internal.rootState = lastSnapshot;
|
|
35
|
+
try {
|
|
36
|
+
replaceExternalStoreState(store, internal, currentSnapshot, { syncImmutable: false });
|
|
37
|
+
} finally {
|
|
38
|
+
internal.rootState = rootState;
|
|
39
|
+
}
|
|
40
|
+
lastSnapshot = currentSnapshot;
|
|
41
|
+
return "handled";
|
|
42
|
+
}
|
|
43
|
+
lastSnapshot = currentSnapshot;
|
|
44
|
+
return "external";
|
|
45
|
+
};
|
|
46
|
+
store._destroyers = /* @__PURE__ */ new Set();
|
|
47
|
+
store._listeners = /* @__PURE__ */ new Set();
|
|
48
|
+
let unsubscribeExternal;
|
|
49
|
+
const cancelReadySubscription = onStoreReady(store, () => {
|
|
50
|
+
replaceMutableAdapterState(internal.rootState ?? rawState, getMutableState(), store.getState(), sanitizeInitialStateValue(snapshotMutableAdapterPureState(store)));
|
|
51
|
+
lastSnapshot = snapshotMutableAdapterPureState(store);
|
|
52
|
+
unsubscribeExternal = subscribe(getMutableState(), () => {
|
|
53
|
+
const change = syncSharedExternalChange();
|
|
54
|
+
if (change === "ignored") return;
|
|
55
|
+
if (change === "external") internal.notifyStateChange?.();
|
|
56
|
+
store._listeners?.forEach((listener) => listener());
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
Object.assign(store, { subscribe: (listener) => {
|
|
60
|
+
internal.assertAlive?.("subscribe");
|
|
61
|
+
store._listeners.add(listener);
|
|
62
|
+
return () => {
|
|
63
|
+
store._listeners?.delete(listener);
|
|
64
|
+
};
|
|
65
|
+
} });
|
|
66
|
+
const baseDestroy = store.destroy;
|
|
67
|
+
let destroyed = false;
|
|
68
|
+
store.destroy = () => {
|
|
69
|
+
if (destroyed) return;
|
|
70
|
+
destroyed = true;
|
|
71
|
+
cancelReadySubscription();
|
|
72
|
+
unsubscribeExternal?.();
|
|
73
|
+
unsubscribeExternal = void 0;
|
|
74
|
+
store._listeners?.clear();
|
|
75
|
+
store._listeners = void 0;
|
|
76
|
+
store._destroyers?.forEach((destroy) => destroy());
|
|
77
|
+
store._destroyers?.clear();
|
|
78
|
+
store._destroyers = void 0;
|
|
79
|
+
baseDestroy();
|
|
80
|
+
};
|
|
81
|
+
store.apply = (state = store.getPureState(), patches) => {
|
|
82
|
+
internal.assertAlive?.("apply");
|
|
83
|
+
isApplyingCoactionState = true;
|
|
84
|
+
try {
|
|
85
|
+
if (!patches) {
|
|
86
|
+
replaceMutableAdapterState(internal.rootState ?? rawState, getMutableState(), store.getState(), state);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
applyMutableAdapterPatches(state, patches, internal.rootState ?? rawState, getMutableState(), store.getState());
|
|
90
|
+
} finally {
|
|
91
|
+
lastSnapshot = snapshotMutableAdapterPureState(store);
|
|
92
|
+
isApplyingCoactionState = false;
|
|
93
|
+
internal.notifyStateChange?.();
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
70
97
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Bind a store to Valtio.
|
|
100
|
+
*/
|
|
101
|
+
const bindValtio = createBinder({
|
|
102
|
+
handleStore,
|
|
103
|
+
handleState: (options) => {
|
|
104
|
+
const descriptors = Object.getOwnPropertyDescriptors(options);
|
|
105
|
+
const copyState = Object.defineProperties({}, descriptors);
|
|
106
|
+
const rawState = Object.defineProperties({}, descriptors);
|
|
107
|
+
return {
|
|
108
|
+
copyState,
|
|
109
|
+
bind: (state) => {
|
|
110
|
+
instancesMap.set(rawState, state);
|
|
111
|
+
return rawState;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
88
115
|
});
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
bindValtio,
|
|
96
|
-
proxy
|
|
97
|
-
};
|
|
116
|
+
/**
|
|
117
|
+
* Adapt a Valtio store type to state type.
|
|
118
|
+
*/
|
|
119
|
+
const adapt = (store) => store;
|
|
120
|
+
//#endregion
|
|
121
|
+
export { adapt, bindValtio, proxy };
|
package/package.json
CHANGED
|
@@ -1,75 +1,69 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coaction/valtio",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "A Coaction integration tool for Valtio",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"state",
|
|
7
6
|
"coaction",
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
"authors": [
|
|
12
|
-
"Michael Lin <unadlib@gmail.com> (https://github.com/unadlib)"
|
|
7
|
+
"proxy",
|
|
8
|
+
"state",
|
|
9
|
+
"valtio"
|
|
13
10
|
],
|
|
14
|
-
"homepage": "https://github.com/
|
|
11
|
+
"homepage": "https://github.com/coactionjs/coaction/tree/main/packages/coaction-valtio#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/coactionjs/coaction/issues"
|
|
14
|
+
},
|
|
15
15
|
"license": "MIT",
|
|
16
|
+
"author": "unadlib",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/coactionjs/coaction.git",
|
|
20
|
+
"directory": "packages/coaction-valtio"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"sideEffects": false,
|
|
16
26
|
"main": "dist/index.js",
|
|
17
27
|
"module": "dist/index.mjs",
|
|
28
|
+
"types": "dist/index.d.ts",
|
|
18
29
|
"exports": {
|
|
19
30
|
".": {
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
31
|
+
"import": {
|
|
32
|
+
"types": "./dist/index.d.mts",
|
|
33
|
+
"default": "./dist/index.mjs"
|
|
34
|
+
},
|
|
35
|
+
"require": {
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"default": "./dist/index.js"
|
|
38
|
+
},
|
|
23
39
|
"default": "./dist/index.mjs"
|
|
24
40
|
},
|
|
25
41
|
"./package.json": "./package.json"
|
|
26
42
|
},
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"dist"
|
|
31
|
-
],
|
|
32
|
-
"repository": {
|
|
33
|
-
"type": "git",
|
|
34
|
-
"url": "https://github.com/unadlib/coaction.git",
|
|
35
|
-
"directory": "packages/coaction-valtio"
|
|
36
|
-
},
|
|
37
|
-
"bugs": {
|
|
38
|
-
"url": "https://github.com/unadlib/coaction/issues"
|
|
39
|
-
},
|
|
40
|
-
"peerDependencies": {
|
|
41
|
-
"coaction": "^1.5.0",
|
|
42
|
-
"mutative": "^1.1.0",
|
|
43
|
-
"valtio": "^2.0.0"
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public",
|
|
45
|
+
"provenance": true
|
|
44
46
|
},
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"optional": true
|
|
48
|
-
},
|
|
49
|
-
"mutative": {
|
|
50
|
-
"optional": true
|
|
51
|
-
},
|
|
52
|
-
"valtio": {
|
|
53
|
-
"optional": true
|
|
54
|
-
}
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"mutability": "^1.2.1"
|
|
55
49
|
},
|
|
56
50
|
"devDependencies": {
|
|
51
|
+
"data-transport": "^5.0.3",
|
|
57
52
|
"mutative": "^1.3.0",
|
|
58
53
|
"valtio": "^2.3.1",
|
|
59
|
-
"coaction": "1.
|
|
54
|
+
"coaction": "2.1.0"
|
|
60
55
|
},
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
|
|
64
|
-
"publishConfig": {
|
|
65
|
-
"access": "public",
|
|
66
|
-
"provenance": true
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"coaction": ">=2.1.0 <3",
|
|
58
|
+
"valtio": "^2.0.0"
|
|
67
59
|
},
|
|
68
|
-
"
|
|
60
|
+
"authors": [
|
|
61
|
+
"Michael Lin <unadlib@gmail.com> (https://github.com/unadlib)"
|
|
62
|
+
],
|
|
69
63
|
"scripts": {
|
|
70
64
|
"clean": "rm -rf dist",
|
|
71
65
|
"test": "vitest run test",
|
|
72
|
-
"build": "
|
|
73
|
-
"dev": "
|
|
66
|
+
"build": "node ../../scripts/build-package.mjs",
|
|
67
|
+
"dev": "node ../../scripts/build-package.mjs --watch"
|
|
74
68
|
}
|
|
75
69
|
}
|