Skip to content

Commit c631e01

Browse files
authored
chore: follow valtio v2-rc.2 change (#18)
* follow valtio v2-rc.2 change * format
1 parent 7b4d8f5 commit c631e01

File tree

4 files changed

+202
-200
lines changed

4 files changed

+202
-200
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"typedoc-plugin-markdown": "^3.17.1",
6161
"typescript": "5.4.5",
6262
"url-loader": "^4.1.1",
63-
"valtio": "^1.13.2",
63+
"valtio": "2.0.0-rc.2",
6464
"verdaccio": "^5.0.4",
6565
"vite": "^5.0.0",
6666
"vitest": "1.6.0",

packages/history-utility/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"tslib": "^2.6.3"
2020
},
2121
"peerDependencies": {
22-
"valtio": ">=1.0.0"
22+
"valtio": ">=2.0.0-rc.2"
2323
},
2424
"type": "commonjs",
2525
"main": "./src/index.js",

packages/history-utility/src/index.ts

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
import {
2-
unstable_buildProxyFunction as buildProxyFunction,
3-
proxy,
4-
ref,
5-
snapshot,
6-
subscribe,
7-
} from 'valtio/vanilla';
8-
import type { INTERNAL_Snapshot as Snapshot } from 'valtio/vanilla';
1+
import { proxy, ref, snapshot, subscribe } from 'valtio/vanilla';
2+
import type { Snapshot } from 'valtio/vanilla';
3+
import { deepClone } from 'valtio/vanilla/utils';
94

105
export type HistoryNode<T> = {
116
/**
@@ -49,27 +44,6 @@ export type HistoryOptions = {
4944
skipSubscribe?: boolean;
5045
};
5146

52-
const isObject = (value: unknown): value is object =>
53-
!!value && typeof value === 'object';
54-
55-
let refSet: WeakSet<object> | undefined;
56-
57-
const deepClone = <T>(value: T): T => {
58-
if (!refSet) {
59-
refSet = buildProxyFunction()[2];
60-
}
61-
if (!isObject(value) || refSet.has(value)) {
62-
return value;
63-
}
64-
const baseObject: T = Array.isArray(value)
65-
? []
66-
: Object.create(Object.getPrototypeOf(value));
67-
Reflect.ownKeys(value).forEach((key) => {
68-
baseObject[key as keyof T] = deepClone(value[key as keyof T]);
69-
});
70-
return baseObject;
71-
};
72-
7347
const normalizeOptions = (
7448
options?: HistoryOptions | boolean
7549
): HistoryOptions => {

0 commit comments

Comments
 (0)