Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: follow valtio v2-rc.2 change #18

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
32 changes: 3 additions & 29 deletions packages/history-utility/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import {
unstable_buildProxyFunction as buildProxyFunction,
proxy,
ref,
snapshot,
subscribe,
} from 'valtio/vanilla';
import type { INTERNAL_Snapshot as Snapshot } from 'valtio/vanilla';
import { proxy, ref, snapshot, subscribe } 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 +44,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