Skip to content

Commit

Permalink
follow valtio v2-rc.2 change
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed Aug 25, 2024
1 parent 7b4d8f5 commit cdef815
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 194 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"typedoc-plugin-markdown": "^3.17.1",
"typescript": "5.4.5",
"url-loader": "^4.1.1",
"valtio": "^1.13.2",
"valtio": "2.0.0-rc.2",
"verdaccio": "^5.0.4",
"vite": "^5.0.0",
"vitest": "1.6.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/history-utility/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"tslib": "^2.6.3"
},
"peerDependencies": {
"valtio": ">=1.0.0"
"valtio": ">=2.0.0-rc.2"
},
"type": "commonjs",
"main": "./src/index.js",
Expand Down
25 changes: 2 additions & 23 deletions packages/history-utility/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {
unstable_buildProxyFunction as buildProxyFunction,
proxy,
ref,
snapshot,
subscribe,
} from 'valtio/vanilla';
import type { INTERNAL_Snapshot as Snapshot } from 'valtio/vanilla';
import type { Snapshot } from 'valtio/vanilla';
import { deepClone } from 'valtio/vanilla/utils';

export type HistoryNode<T> = {
/**
Expand Down Expand Up @@ -49,27 +49,6 @@ export type HistoryOptions = {
skipSubscribe?: boolean;
};

const isObject = (value: unknown): value is object =>
!!value && typeof value === 'object';

let refSet: WeakSet<object> | undefined;

const deepClone = <T>(value: T): T => {
if (!refSet) {
refSet = buildProxyFunction()[2];
}
if (!isObject(value) || refSet.has(value)) {
return value;
}
const baseObject: T = Array.isArray(value)
? []
: Object.create(Object.getPrototypeOf(value));
Reflect.ownKeys(value).forEach((key) => {
baseObject[key as keyof T] = deepClone(value[key as keyof T]);
});
return baseObject;
};

const normalizeOptions = (
options?: HistoryOptions | boolean
): HistoryOptions => {
Expand Down
Loading

0 comments on commit cdef815

Please sign in to comment.