mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-05-11 23:58:31 +08:00
refactor: replace shortid with nanoid. closes #7858
This commit is contained in:
@@ -32,15 +32,14 @@
|
||||
"@react-navigation/routers": "^5.2.0",
|
||||
"escape-string-regexp": "^2.0.0",
|
||||
"query-string": "^6.11.1",
|
||||
"nanoid": "^3.0.2",
|
||||
"react-is": "^16.13.0",
|
||||
"shortid": "^2.2.15",
|
||||
"use-subscription": "^1.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@react-native-community/bob": "^0.10.0",
|
||||
"@types/react": "^16.9.23",
|
||||
"@types/react-is": "^16.7.1",
|
||||
"@types/shortid": "^0.0.29",
|
||||
"@types/use-subscription": "^1.0.0",
|
||||
"del-cli": "^3.0.0",
|
||||
"react": "~16.9.0",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as React from 'react';
|
||||
import shortid from 'shortid';
|
||||
import { nanoid } from 'nanoid';
|
||||
import { SingleNavigatorContext } from './EnsureSingleNavigator';
|
||||
|
||||
/**
|
||||
@@ -7,7 +7,7 @@ import { SingleNavigatorContext } from './EnsureSingleNavigator';
|
||||
* This is used to prevent multiple navigators under a single container or screen.
|
||||
*/
|
||||
export default function useRegisterNavigator() {
|
||||
const [key] = React.useState(() => shortid());
|
||||
const [key] = React.useState(() => nanoid());
|
||||
const container = React.useContext(SingleNavigatorContext);
|
||||
|
||||
if (container === undefined) {
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
"clean": "del lib"
|
||||
},
|
||||
"dependencies": {
|
||||
"shortid": "^2.2.15"
|
||||
"nanoid": "^3.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@react-native-community/bob": "^0.10.0",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import shortid from 'shortid';
|
||||
import { nanoid } from 'nanoid';
|
||||
import { CommonNavigationAction, NavigationState, PartialState } from './types';
|
||||
|
||||
/**
|
||||
@@ -55,9 +55,7 @@ const BaseRouter = {
|
||||
return {
|
||||
...nextState,
|
||||
routes: nextState.routes.map((route) =>
|
||||
route.key
|
||||
? route
|
||||
: { ...route, key: `${route.name}-${shortid()}` }
|
||||
route.key ? route : { ...route, key: `${route.name}-${nanoid()}` }
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import shortid from 'shortid';
|
||||
import { nanoid } from 'nanoid';
|
||||
import {
|
||||
PartialState,
|
||||
CommonNavigationAction,
|
||||
@@ -115,7 +115,7 @@ export default function DrawerRouter(
|
||||
...state,
|
||||
stale: false,
|
||||
type: 'drawer',
|
||||
key: `drawer-${shortid()}`,
|
||||
key: `drawer-${nanoid()}`,
|
||||
};
|
||||
},
|
||||
|
||||
@@ -136,7 +136,7 @@ export default function DrawerRouter(
|
||||
return {
|
||||
...state,
|
||||
type: 'drawer',
|
||||
key: `drawer-${shortid()}`,
|
||||
key: `drawer-${nanoid()}`,
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import shortid from 'shortid';
|
||||
import { nanoid } from 'nanoid';
|
||||
import BaseRouter from './BaseRouter';
|
||||
import {
|
||||
NavigationState,
|
||||
@@ -113,12 +113,12 @@ export default function StackRouter(options: StackRouterOptions) {
|
||||
return {
|
||||
stale: false,
|
||||
type: 'stack',
|
||||
key: `stack-${shortid()}`,
|
||||
key: `stack-${nanoid()}`,
|
||||
index: 0,
|
||||
routeNames,
|
||||
routes: [
|
||||
{
|
||||
key: `${initialRouteName}-${shortid()}`,
|
||||
key: `${initialRouteName}-${nanoid()}`,
|
||||
name: initialRouteName,
|
||||
params: routeParamList[initialRouteName],
|
||||
},
|
||||
@@ -139,7 +139,7 @@ export default function StackRouter(options: StackRouterOptions) {
|
||||
(route) =>
|
||||
({
|
||||
...route,
|
||||
key: route.key || `${route.name}-${shortid()}`,
|
||||
key: route.key || `${route.name}-${nanoid()}`,
|
||||
params:
|
||||
routeParamList[route.name] !== undefined
|
||||
? {
|
||||
@@ -157,7 +157,7 @@ export default function StackRouter(options: StackRouterOptions) {
|
||||
: routeNames[0];
|
||||
|
||||
routes.push({
|
||||
key: `${initialRouteName}-${shortid()}`,
|
||||
key: `${initialRouteName}-${nanoid()}`,
|
||||
name: initialRouteName,
|
||||
params: routeParamList[initialRouteName],
|
||||
});
|
||||
@@ -166,7 +166,7 @@ export default function StackRouter(options: StackRouterOptions) {
|
||||
return {
|
||||
stale: false,
|
||||
type: 'stack',
|
||||
key: `stack-${shortid()}`,
|
||||
key: `stack-${nanoid()}`,
|
||||
index: routes.length - 1,
|
||||
routeNames,
|
||||
routes,
|
||||
@@ -186,7 +186,7 @@ export default function StackRouter(options: StackRouterOptions) {
|
||||
: routeNames[0];
|
||||
|
||||
routes.push({
|
||||
key: `${initialRouteName}-${shortid()}`,
|
||||
key: `${initialRouteName}-${nanoid()}`,
|
||||
name: initialRouteName,
|
||||
params: routeParamList[initialRouteName],
|
||||
});
|
||||
@@ -238,7 +238,7 @@ export default function StackRouter(options: StackRouterOptions) {
|
||||
routes: state.routes.map((route, i) =>
|
||||
i === index
|
||||
? {
|
||||
key: key !== undefined ? key : `${name}-${shortid()}`,
|
||||
key: key !== undefined ? key : `${name}-${nanoid()}`,
|
||||
name,
|
||||
params:
|
||||
routeParamList[name] !== undefined
|
||||
@@ -263,7 +263,7 @@ export default function StackRouter(options: StackRouterOptions) {
|
||||
{
|
||||
key:
|
||||
action.payload.key === undefined
|
||||
? `${action.payload.name}-${shortid()}`
|
||||
? `${action.payload.name}-${nanoid()}`
|
||||
: action.payload.key,
|
||||
name: action.payload.name,
|
||||
params:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import shortid from 'shortid';
|
||||
import { nanoid } from 'nanoid';
|
||||
import BaseRouter from './BaseRouter';
|
||||
import {
|
||||
NavigationState,
|
||||
@@ -126,7 +126,7 @@ export default function TabRouter({
|
||||
|
||||
const routes = routeNames.map((name) => ({
|
||||
name,
|
||||
key: `${name}-${shortid()}`,
|
||||
key: `${name}-${nanoid()}`,
|
||||
params: routeParamList[name],
|
||||
}));
|
||||
|
||||
@@ -135,7 +135,7 @@ export default function TabRouter({
|
||||
return {
|
||||
stale: false,
|
||||
type: 'tab',
|
||||
key: `tab-${shortid()}`,
|
||||
key: `tab-${nanoid()}`,
|
||||
index,
|
||||
routeNames,
|
||||
history,
|
||||
@@ -161,7 +161,7 @@ export default function TabRouter({
|
||||
key:
|
||||
route && route.name === name && route.key
|
||||
? route.key
|
||||
: `${name}-${shortid()}`,
|
||||
: `${name}-${nanoid()}`,
|
||||
params:
|
||||
routeParamList[name] !== undefined
|
||||
? {
|
||||
@@ -195,7 +195,7 @@ export default function TabRouter({
|
||||
return {
|
||||
stale: false,
|
||||
type: 'tab',
|
||||
key: `tab-${shortid()}`,
|
||||
key: `tab-${nanoid()}`,
|
||||
index,
|
||||
routeNames,
|
||||
history,
|
||||
@@ -208,7 +208,7 @@ export default function TabRouter({
|
||||
(name) =>
|
||||
state.routes.find((r) => r.name === name) || {
|
||||
name,
|
||||
key: `${name}-${shortid()}`,
|
||||
key: `${name}-${nanoid()}`,
|
||||
params: routeParamList[name],
|
||||
}
|
||||
);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import BaseRouter from '../BaseRouter';
|
||||
import * as CommonActions from '../CommonActions';
|
||||
|
||||
jest.mock('shortid', () => () => 'test');
|
||||
jest.mock('nanoid', () => ({ nanoid: () => 'test' }));
|
||||
|
||||
const STATE = {
|
||||
stale: false as const,
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
DrawerNavigationState,
|
||||
} from '..';
|
||||
|
||||
jest.mock('shortid', () => () => 'test');
|
||||
jest.mock('nanoid', () => ({ nanoid: () => 'test' }));
|
||||
|
||||
it('gets initial state from route names and params with initialRouteName', () => {
|
||||
const router = DrawerRouter({ initialRouteName: 'baz' });
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { CommonActions, StackRouter, StackActions } from '..';
|
||||
|
||||
jest.mock('shortid', () => () => 'test');
|
||||
jest.mock('nanoid', () => ({ nanoid: () => 'test' }));
|
||||
|
||||
it('gets initial state from route names and params with initialRouteName', () => {
|
||||
const router = StackRouter({ initialRouteName: 'baz' });
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { CommonActions, TabRouter, TabActions, TabNavigationState } from '..';
|
||||
|
||||
jest.mock('shortid', () => () => 'test');
|
||||
jest.mock('nanoid', () => ({ nanoid: () => 'test' }));
|
||||
|
||||
it('gets initial state from route names and params with initialRouteName', () => {
|
||||
const router = TabRouter({ initialRouteName: 'baz' });
|
||||
|
||||
20
yarn.lock
20
yarn.lock
@@ -3663,11 +3663,6 @@
|
||||
"@types/glob" "*"
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/shortid@^0.0.29":
|
||||
version "0.0.29"
|
||||
resolved "https://registry.yarnpkg.com/@types/shortid/-/shortid-0.0.29.tgz#8093ee0416a6e2bf2aa6338109114b3fbffa0e9b"
|
||||
integrity sha1-gJPuBBam4r8qpjOBCRFLP7/6Dps=
|
||||
|
||||
"@types/source-list-map@*":
|
||||
version "0.1.2"
|
||||
resolved "https://registry.yarnpkg.com/@types/source-list-map/-/source-list-map-0.1.2.tgz#0078836063ffaf17412349bba364087e0ac02ec9"
|
||||
@@ -13131,10 +13126,10 @@ nan@^2.12.1, nan@^2.14.0:
|
||||
resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.0.tgz#7818f722027b2459a86f0295d434d1fc2336c52c"
|
||||
integrity sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==
|
||||
|
||||
nanoid@^2.1.0:
|
||||
version "2.1.11"
|
||||
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-2.1.11.tgz#ec24b8a758d591561531b4176a01e3ab4f0f0280"
|
||||
integrity sha512-s/snB+WGm6uwi0WjsZdaVcuf3KJXlfGl2LcxgwkEwJF0D/BWzVWAZW/XY4bFaiR7s0Jk3FPvlnepg1H1b1UwlA==
|
||||
nanoid@^3.0.2:
|
||||
version "3.0.2"
|
||||
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.0.2.tgz#37e91e6f5277ce22335be473e2a5db1bd96dd026"
|
||||
integrity sha512-WOjyy/xu3199NlQiQWlx7VbspSFlGtOxa1bRX9ebmXOnp1fje4bJfjPs1wLQ8jZbJUfD+yceJmw879ZSaVJkdQ==
|
||||
|
||||
nanomatch@^1.2.9:
|
||||
version "1.2.13"
|
||||
@@ -16521,13 +16516,6 @@ shellwords@^0.1.1:
|
||||
resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b"
|
||||
integrity sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww==
|
||||
|
||||
shortid@^2.2.15:
|
||||
version "2.2.15"
|
||||
resolved "https://registry.yarnpkg.com/shortid/-/shortid-2.2.15.tgz#2b902eaa93a69b11120373cd42a1f1fe4437c122"
|
||||
integrity sha512-5EaCy2mx2Jgc/Fdn9uuDuNIIfWBpzY4XIlhoqtXF6qsf+/+SGZ+FxDdX/ZsMZiWupIWNqAEmiNY4RC+LSmCeOw==
|
||||
dependencies:
|
||||
nanoid "^2.1.0"
|
||||
|
||||
side-channel@^1.0.2:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/side-channel/-/side-channel-1.0.2.tgz#df5d1abadb4e4bf4af1cd8852bf132d2f7876947"
|
||||
|
||||
Reference in New Issue
Block a user