Download next.js/packages/next/src/shared/lib/router/utils/compare-states.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 886 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/shared/lib/router/utils/compare-states.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/packages/next/src/shared/lib/router/utils/compare-states.ts
-
curl -L -o compare-states.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/shared/lib/router/utils/compare-states.ts
886 Bytes
| import type { default as Router } from '../router' | |
| export function compareRouterStates(a: Router['state'], b: Router['state']) { | |
| const stateKeys = Object.keys(a) | |
| if (stateKeys.length !== Object.keys(b).length) return false | |
| for (let i = stateKeys.length; i--; ) { | |
| const key = stateKeys[i] | |
| if (key === 'query') { | |
| const queryKeys = Object.keys(a.query) | |
| if (queryKeys.length !== Object.keys(b.query).length) { | |
| return false | |
| } | |
| for (let j = queryKeys.length; j--; ) { | |
| const queryKey = queryKeys[j] | |
| if ( | |
| !b.query.hasOwnProperty(queryKey) || | |
| a.query[queryKey] !== b.query[queryKey] | |
| ) { | |
| return false | |
| } | |
| } | |
| } else if ( | |
| !b.hasOwnProperty(key) || | |
| a[key as keyof Router['state']] !== b[key as keyof Router['state']] | |
| ) { | |
| return false | |
| } | |
| } | |
| return true | |
| } | |