@react-navigation/core 7.0.0-rc.14 → 7.0.0-rc.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/getPathFromState.js +10 -7
- package/lib/commonjs/getPathFromState.js.map +1 -1
- package/lib/commonjs/getStateFromPath.js +7 -5
- package/lib/commonjs/getStateFromPath.js.map +1 -1
- package/lib/module/getPathFromState.js +10 -7
- package/lib/module/getPathFromState.js.map +1 -1
- package/lib/module/getStateFromPath.js +7 -5
- package/lib/module/getStateFromPath.js.map +1 -1
- package/lib/typescript/commonjs/src/getPathFromState.d.ts.map +1 -1
- package/lib/typescript/commonjs/tsconfig.build.tsbuildinfo +1 -1
- package/lib/typescript/module/src/getPathFromState.d.ts.map +1 -1
- package/lib/typescript/module/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/getPathFromState.tsx +19 -12
- package/src/getStateFromPath.tsx +11 -8
package/src/getPathFromState.tsx
CHANGED
|
@@ -37,10 +37,24 @@ const getActiveRoute = (state: State): { name: string; params?: object } => {
|
|
|
37
37
|
return route;
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
PathConfigMap<{}
|
|
42
|
-
Record<string, ConfigItem
|
|
43
|
-
|
|
40
|
+
const cachedNormalizedConfigs = new WeakMap<
|
|
41
|
+
PathConfigMap<{}>,
|
|
42
|
+
Record<string, ConfigItem>
|
|
43
|
+
>();
|
|
44
|
+
|
|
45
|
+
const getNormalizedConfigs = (options?: Options<{}>) => {
|
|
46
|
+
if (!options?.screens) return {};
|
|
47
|
+
|
|
48
|
+
const cached = cachedNormalizedConfigs.get(options?.screens);
|
|
49
|
+
|
|
50
|
+
if (cached) return cached;
|
|
51
|
+
|
|
52
|
+
const normalizedConfigs = createNormalizedConfigs(options.screens);
|
|
53
|
+
|
|
54
|
+
cachedNormalizedConfigs.set(options.screens, normalizedConfigs);
|
|
55
|
+
|
|
56
|
+
return normalizedConfigs;
|
|
57
|
+
};
|
|
44
58
|
|
|
45
59
|
/**
|
|
46
60
|
* Utility to serialize a navigation state object to a path string.
|
|
@@ -85,14 +99,7 @@ export function getPathFromState<ParamList extends {}>(
|
|
|
85
99
|
validatePathConfig(options);
|
|
86
100
|
}
|
|
87
101
|
|
|
88
|
-
|
|
89
|
-
if (cachedNormalizedConfigs[0] !== options?.screens) {
|
|
90
|
-
cachedNormalizedConfigs = [
|
|
91
|
-
options?.screens,
|
|
92
|
-
options?.screens ? createNormalizedConfigs(options.screens) : {},
|
|
93
|
-
];
|
|
94
|
-
}
|
|
95
|
-
const configs: Record<string, ConfigItem> = cachedNormalizedConfigs[1];
|
|
102
|
+
const configs = getNormalizedConfigs(options);
|
|
96
103
|
|
|
97
104
|
let path = '/';
|
|
98
105
|
let current: State | undefined = state;
|
package/src/getStateFromPath.tsx
CHANGED
|
@@ -169,19 +169,22 @@ export function getStateFromPath<ParamList extends {}>(
|
|
|
169
169
|
/**
|
|
170
170
|
* Reference to the last used config resources. This is used to avoid recomputing the config resources when the options are the same.
|
|
171
171
|
*/
|
|
172
|
-
|
|
173
|
-
undefined,
|
|
174
|
-
prepareConfigResources(),
|
|
175
|
-
];
|
|
172
|
+
const cachedConfigResources = new WeakMap<Options<{}>, ConfigResources>();
|
|
176
173
|
|
|
177
174
|
function getConfigResources<ParamList extends {}>(
|
|
178
175
|
options: Options<ParamList> | undefined
|
|
179
176
|
) {
|
|
180
|
-
if (
|
|
181
|
-
|
|
182
|
-
|
|
177
|
+
if (!options) return prepareConfigResources();
|
|
178
|
+
|
|
179
|
+
const cached = cachedConfigResources.get(options);
|
|
180
|
+
|
|
181
|
+
if (cached) return cached;
|
|
182
|
+
|
|
183
|
+
const resources = prepareConfigResources(options);
|
|
184
|
+
|
|
185
|
+
cachedConfigResources.set(options, resources);
|
|
183
186
|
|
|
184
|
-
return
|
|
187
|
+
return resources;
|
|
185
188
|
}
|
|
186
189
|
|
|
187
190
|
function prepareConfigResources(options?: Options<{}>) {
|