hybrid-navigation 5.0.0 → 5.1.1
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/android/src/main/java/com/navigation/androidx/AwesomeActivity.java +2 -4
- package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +48 -2
- package/android/src/main/java/com/navigation/androidx/DefaultTabBarProvider.java +2 -2
- package/android/src/main/java/com/navigation/androidx/FragmentHelper.java +7 -0
- package/android/src/main/java/com/navigation/androidx/PresentationDelegate.java +2 -4
- package/android/src/main/java/com/navigation/androidx/StackFragment.java +3 -0
- package/android/src/main/java/com/navigation/androidx/TabBarFragment.java +50 -0
- package/android/src/main/java/com/navigation/androidx/TabBarItem.java +4 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/DispatchResult.java +16 -4
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +19 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDRootView.java +17 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +66 -7
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +116 -18
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationCommandQueue.java +8 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +376 -8
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +72 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +26 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +134 -12
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +35 -3
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +29 -4
- package/dist/NativeEvent.d.ts +15 -0
- package/dist/NativeNavigation.d.ts +8 -0
- package/dist/Navigation.d.ts +14 -1
- package/dist/Navigation.js +153 -12
- package/dist/NavigationComponentWrap.d.ts +3 -2
- package/dist/Navigator.d.ts +3 -2
- package/dist/Navigator.js +28 -9
- package/dist/Options.d.ts +12 -2
- package/dist/Route.d.ts +70 -5
- package/dist/defineRoutes.d.ts +19 -0
- package/dist/defineRoutes.js +6 -0
- package/dist/handler/DispatchCommandHandler.d.ts +16 -1
- package/dist/handler/DispatchCommandHandler.js +63 -5
- package/dist/handler/LayoutCommandHandler.d.ts +1 -0
- package/dist/handler/LayoutCommandHandler.js +3 -0
- package/dist/handler/LeaveGuardHandler.d.ts +17 -0
- package/dist/handler/LeaveGuardHandler.js +350 -0
- package/dist/handler/LifecycleEventHandler.d.ts +7 -3
- package/dist/handler/LifecycleEventHandler.js +36 -3
- package/dist/handler/PresentationCoordinator.d.ts +24 -0
- package/dist/handler/PresentationCoordinator.js +456 -0
- package/dist/handler/ResultEventHandler.d.ts +7 -0
- package/dist/handler/ResultEventHandler.js +13 -5
- package/dist/handler/TabEventHandler.d.ts +8 -0
- package/dist/handler/TabEventHandler.js +25 -0
- package/dist/hooks.d.ts +3 -1
- package/dist/hooks.js +20 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +3 -0
- package/dist/reveal.d.ts +46 -0
- package/dist/reveal.js +431 -0
- package/dist/routeGraph.d.ts +12 -0
- package/dist/routeGraph.js +68 -0
- package/dist/router/index.js +5 -41
- package/dist/router/tabs.d.ts +1 -0
- package/dist/store.d.ts +2 -0
- package/dist/store.js +4 -0
- package/dist/testing.d.ts +79 -0
- package/dist/testing.js +251 -0
- package/ios/HBDGlobalStyle.h +3 -0
- package/ios/HBDGlobalStyle.mm +13 -0
- package/ios/HybridNavigation.h +1 -0
- package/ios/Navigator/HBDScreenNavigator.mm +250 -11
- package/ios/Navigator/HBDStackNavigator.mm +50 -7
- package/ios/Navigator/HBDTabNavigator.mm +33 -5
- package/ios/React/HBDNativeNavigation.mm +73 -12
- package/ios/React/HBDNavigator.h +8 -0
- package/ios/React/HBDOrientationCoordinator.h +2 -0
- package/ios/React/HBDOrientationCoordinator.mm +27 -0
- package/ios/React/HBDReactBridgeManager.h +10 -0
- package/ios/React/HBDReactBridgeManager.mm +48 -2
- package/ios/ViewController/HBDNavigationController.mm +14 -0
- package/ios/ViewController/HBDReactViewController.h +6 -0
- package/ios/ViewController/HBDReactViewController.mm +177 -1
- package/ios/ViewController/HBDTabBarController.h +11 -0
- package/ios/ViewController/HBDTabBarController.mm +170 -3
- package/ios/ViewController/HBDTabBarRenderer.h +28 -0
- package/ios/ViewController/HBDViewController.h +1 -0
- package/ios/ViewController/HBDViewController.mm +57 -9
- package/ios/ViewController/UIViewController+HBD.h +1 -0
- package/ios/ViewController/UIViewController+HBD.mm +17 -4
- package/package.json +3 -1
- package/src/NativeEvent.ts +17 -0
- package/src/NativeNavigation.ts +9 -0
- package/src/Navigation.ts +228 -12
- package/src/NavigationComponentWrap.tsx +11 -2
- package/src/Navigator.ts +38 -9
- package/src/Options.ts +9 -2
- package/src/Route.ts +102 -6
- package/src/defineRoutes.ts +46 -0
- package/src/handler/DispatchCommandHandler.ts +110 -11
- package/src/handler/LayoutCommandHandler.ts +4 -0
- package/src/handler/LeaveGuardHandler.ts +436 -0
- package/src/handler/LifecycleEventHandler.ts +85 -38
- package/src/handler/PresentationCoordinator.ts +566 -0
- package/src/handler/ResultEventHandler.ts +23 -9
- package/src/handler/TabEventHandler.ts +31 -0
- package/src/hooks.ts +37 -1
- package/src/index.ts +11 -0
- package/src/reveal.ts +565 -0
- package/src/routeGraph.ts +87 -0
- package/src/router/index.ts +5 -40
- package/src/router/tabs.ts +1 -0
- package/src/store.ts +5 -0
- package/src/testing.ts +395 -0
- package/testing.d.ts +1 -0
- package/testing.js +3 -0
package/src/Route.ts
CHANGED
|
@@ -1,15 +1,39 @@
|
|
|
1
1
|
import type { NavigationItem } from './Options';
|
|
2
|
-
import type { CustomLayoutMap, NavigationParamList } from './index';
|
|
2
|
+
import type { CustomLayoutMap, NavigationParamList, NavigationTypeConfig } from './index';
|
|
3
3
|
|
|
4
4
|
export type Visibility = 'visible' | 'invisible' | 'pending';
|
|
5
5
|
|
|
6
6
|
export type SceneLifecycleState = 'created' | 'visible' | 'invisible' | 'destroyed';
|
|
7
7
|
|
|
8
|
+
export interface SceneInfo {
|
|
9
|
+
sceneId: string;
|
|
10
|
+
moduleName?: string;
|
|
11
|
+
mode: LayoutMode;
|
|
12
|
+
presentingId: string | null;
|
|
13
|
+
state: SceneLifecycleState;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface TabPressEvent {
|
|
17
|
+
index: number;
|
|
18
|
+
tabKey?: string;
|
|
19
|
+
previousIndex: number;
|
|
20
|
+
reselected: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type TabPressListener = (event: TabPressEvent) => void;
|
|
24
|
+
|
|
25
|
+
export interface NavigationSnapshot {
|
|
26
|
+
rootGeneration: number;
|
|
27
|
+
currentRoute: Route | null;
|
|
28
|
+
layers: RouteGraph[];
|
|
29
|
+
}
|
|
30
|
+
|
|
8
31
|
export type DispatchResultCode =
|
|
9
32
|
| 'ok'
|
|
10
33
|
| 'intercepted'
|
|
11
34
|
| 'scene_not_found'
|
|
12
35
|
| 'already_presenting'
|
|
36
|
+
| 'covered'
|
|
13
37
|
| 'not_ready'
|
|
14
38
|
| 'superseded'
|
|
15
39
|
| 'invalid_action'
|
|
@@ -19,6 +43,65 @@ export interface DispatchResult {
|
|
|
19
43
|
ok: boolean;
|
|
20
44
|
code: DispatchResultCode;
|
|
21
45
|
message?: string;
|
|
46
|
+
sceneId?: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type CloseTarget = 'self' | 'presented';
|
|
50
|
+
|
|
51
|
+
export type CoveredPolicy = 'fail' | 'defer';
|
|
52
|
+
|
|
53
|
+
export type SceneExitRestoreReason = DispatchResultCode | 'exit_error';
|
|
54
|
+
|
|
55
|
+
export interface SceneExitHandler {
|
|
56
|
+
onExit: () => void | Promise<void>;
|
|
57
|
+
onRestore?: (reason: SceneExitRestoreReason) => void;
|
|
58
|
+
/** Optional timeout in milliseconds for async onExit(); defaults to 1200ms. */
|
|
59
|
+
exitTimeoutMs?: number;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface CloseSelfOptions<T extends ResultMap = ResultMap> {
|
|
63
|
+
result?: {
|
|
64
|
+
code: number;
|
|
65
|
+
data?: T | null;
|
|
66
|
+
};
|
|
67
|
+
onCovered?: CoveredPolicy;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export type LeaveAction =
|
|
71
|
+
| 'back'
|
|
72
|
+
| 'pop'
|
|
73
|
+
| 'popTo'
|
|
74
|
+
| 'popToRoot'
|
|
75
|
+
| 'dismiss'
|
|
76
|
+
| 'hideModal'
|
|
77
|
+
| 'close'
|
|
78
|
+
| 'redirectTo';
|
|
79
|
+
|
|
80
|
+
export interface BeforeRemoveEvent {
|
|
81
|
+
sceneId: string;
|
|
82
|
+
action: LeaveAction;
|
|
83
|
+
proceed: () => Promise<DispatchResult>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface BeforeRemoveOptions {
|
|
87
|
+
actions?: LeaveAction[];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export type BeforeRemoveListener = (event: BeforeRemoveEvent) => void | Promise<void>;
|
|
91
|
+
|
|
92
|
+
export interface InitialMetrics {
|
|
93
|
+
insets: {
|
|
94
|
+
top: number;
|
|
95
|
+
right: number;
|
|
96
|
+
bottom: number;
|
|
97
|
+
left: number;
|
|
98
|
+
};
|
|
99
|
+
frame: {
|
|
100
|
+
x: number;
|
|
101
|
+
y: number;
|
|
102
|
+
width: number;
|
|
103
|
+
height: number;
|
|
104
|
+
};
|
|
22
105
|
}
|
|
23
106
|
|
|
24
107
|
export interface SetRootOptions {
|
|
@@ -42,8 +125,18 @@ export type ScreenRoute<
|
|
|
42
125
|
|
|
43
126
|
export type HasTypedRoutes = keyof NavigationParamList extends never ? false : true;
|
|
44
127
|
|
|
128
|
+
export type AllowUnregisteredRoutes = NavigationTypeConfig extends {
|
|
129
|
+
allowUnregisteredRoutes: true;
|
|
130
|
+
}
|
|
131
|
+
? true
|
|
132
|
+
: false;
|
|
133
|
+
|
|
134
|
+
export type RegisteredRouteName = Extract<keyof NavigationParamList, string>;
|
|
135
|
+
|
|
45
136
|
export type RouteName = HasTypedRoutes extends true
|
|
46
|
-
?
|
|
137
|
+
? AllowUnregisteredRoutes extends true
|
|
138
|
+
? RegisteredRouteName | (string & {})
|
|
139
|
+
: RegisteredRouteName
|
|
47
140
|
: string;
|
|
48
141
|
|
|
49
142
|
type RawRouteEntry<Name extends string> = Name extends keyof NavigationParamList
|
|
@@ -88,9 +181,11 @@ type RequiredKeysOf<T> = {
|
|
|
88
181
|
export type IsPropsRequired<P> = [RequiredKeysOf<P>] extends [never] ? false : true;
|
|
89
182
|
|
|
90
183
|
export type ScreenPropsArgs<Name extends string> = HasTypedRoutes extends true
|
|
91
|
-
?
|
|
92
|
-
?
|
|
93
|
-
|
|
184
|
+
? [Name] extends [RegisteredRouteName]
|
|
185
|
+
? IsPropsRequired<RoutePropsOf<Name>> extends true
|
|
186
|
+
? [props: RoutePropsOf<Name>, options?: NavigationItem]
|
|
187
|
+
: [props?: RoutePropsOf<Name>, options?: NavigationItem]
|
|
188
|
+
: [props?: Record<string, any>, options?: NavigationItem]
|
|
94
189
|
: [props?: Record<string, any>, options?: NavigationItem];
|
|
95
190
|
|
|
96
191
|
export type Screen<Name extends RouteName = RouteName> = HasTypedRoutes extends true
|
|
@@ -125,6 +220,7 @@ export interface Tabs {
|
|
|
125
220
|
children: Array<Layout>;
|
|
126
221
|
options?: {
|
|
127
222
|
selectedIndex?: number;
|
|
223
|
+
renderer?: string;
|
|
128
224
|
};
|
|
129
225
|
};
|
|
130
226
|
}
|
|
@@ -172,7 +268,7 @@ export interface RouteGraph {
|
|
|
172
268
|
|
|
173
269
|
export interface RouteConfig {
|
|
174
270
|
path?: string;
|
|
175
|
-
dependency?:
|
|
271
|
+
dependency?: string;
|
|
176
272
|
mode?: RouteMode;
|
|
177
273
|
options?: NavigationItem;
|
|
178
274
|
lazy?: boolean;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
2
|
+
import type { NavigationItem } from './Options';
|
|
3
|
+
import type { RouteMode, ScreenRoute } from './Route';
|
|
4
|
+
|
|
5
|
+
export interface RouteDefinition<
|
|
6
|
+
Name extends string = string,
|
|
7
|
+
Props extends Record<string, any> = Record<never, never>,
|
|
8
|
+
Result = unknown,
|
|
9
|
+
> {
|
|
10
|
+
readonly name: Name;
|
|
11
|
+
readonly load: () => ComponentType<any>;
|
|
12
|
+
readonly options?: NavigationItem;
|
|
13
|
+
readonly path?: string;
|
|
14
|
+
readonly dependency?: string;
|
|
15
|
+
readonly mode?: RouteMode;
|
|
16
|
+
readonly lazy?: boolean;
|
|
17
|
+
readonly __types?: ScreenRoute<Props, Result>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type RouteDefinitionInput<
|
|
21
|
+
Name extends string,
|
|
22
|
+
Props extends Record<string, any> = Record<never, never>,
|
|
23
|
+
Result = unknown,
|
|
24
|
+
> = Omit<RouteDefinition<Name, Props, Result>, '__types'>;
|
|
25
|
+
|
|
26
|
+
export function defineRoute<
|
|
27
|
+
const Name extends string,
|
|
28
|
+
Props extends Record<string, any> = Record<never, never>,
|
|
29
|
+
Result = unknown,
|
|
30
|
+
>(
|
|
31
|
+
definition: RouteDefinitionInput<Name, Props, Result>,
|
|
32
|
+
): RouteDefinition<Name, Props, Result> {
|
|
33
|
+
return definition;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function defineRoutes<const T extends readonly RouteDefinition<any, any, any>[]>(
|
|
37
|
+
routes: T,
|
|
38
|
+
): T {
|
|
39
|
+
return routes;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type RouteParamListOf<T extends readonly RouteDefinition<any, any, any>[]> = {
|
|
43
|
+
[R in T[number] as R['name']]: R extends RouteDefinition<any, infer P, infer Res>
|
|
44
|
+
? ScreenRoute<P, Res>
|
|
45
|
+
: ScreenRoute<Record<string, any>, unknown>;
|
|
46
|
+
};
|
|
@@ -1,12 +1,30 @@
|
|
|
1
1
|
import NativeNavigation, { DispatchResultWire } from '../NativeNavigation';
|
|
2
2
|
import { NavigationItem } from '../Options';
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
BuildInLayout,
|
|
5
|
+
CloseTarget,
|
|
6
|
+
CoveredPolicy,
|
|
7
|
+
DispatchResult,
|
|
8
|
+
DispatchResultCode,
|
|
9
|
+
Layout,
|
|
10
|
+
} from '../Route';
|
|
11
|
+
import { resultHandler } from './ResultEventHandler';
|
|
12
|
+
|
|
13
|
+
const INTERCEPT_CHECKED_PROP = '__hbdInterceptChecked';
|
|
14
|
+
const INTERNAL_DISPATCH_PROPS = [
|
|
15
|
+
INTERCEPT_CHECKED_PROP,
|
|
16
|
+
'onCovered',
|
|
17
|
+
'bypassBeforeRemove',
|
|
18
|
+
'__hbdBypassBeforeRemove',
|
|
19
|
+
'__hbdApprovedBeforeRemoveScenes',
|
|
20
|
+
] as const;
|
|
4
21
|
|
|
5
22
|
const VALID_DISPATCH_CODES = new Set<DispatchResultCode>([
|
|
6
23
|
'ok',
|
|
7
24
|
'intercepted',
|
|
8
25
|
'scene_not_found',
|
|
9
26
|
'already_presenting',
|
|
27
|
+
'covered',
|
|
10
28
|
'not_ready',
|
|
11
29
|
'superseded',
|
|
12
30
|
'invalid_action',
|
|
@@ -24,9 +42,14 @@ export function normalizeDispatchResult(
|
|
|
24
42
|
: wire.ok
|
|
25
43
|
? 'ok'
|
|
26
44
|
: 'invalid_action';
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
45
|
+
const result: DispatchResult = { ok: Boolean(wire.ok), code };
|
|
46
|
+
if (wire.message) {
|
|
47
|
+
result.message = wire.message;
|
|
48
|
+
}
|
|
49
|
+
if (wire.sceneId) {
|
|
50
|
+
result.sceneId = wire.sceneId;
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
30
53
|
}
|
|
31
54
|
|
|
32
55
|
export interface DispatchParams {
|
|
@@ -37,7 +60,15 @@ export interface DispatchParams {
|
|
|
37
60
|
to?: string | number;
|
|
38
61
|
layout?: BuildInLayout | Layout;
|
|
39
62
|
popToRoot?: boolean;
|
|
63
|
+
tabKey?: string;
|
|
40
64
|
requestCode?: number;
|
|
65
|
+
target?: CloseTarget;
|
|
66
|
+
onCovered?: CoveredPolicy;
|
|
67
|
+
result?: {
|
|
68
|
+
code: number;
|
|
69
|
+
data?: any;
|
|
70
|
+
};
|
|
71
|
+
bypassBeforeRemove?: boolean;
|
|
41
72
|
props?: object;
|
|
42
73
|
options?: NavigationItem;
|
|
43
74
|
[index: string]: any;
|
|
@@ -55,14 +86,26 @@ export type NavigationInterceptor = (
|
|
|
55
86
|
params: InterceptParams,
|
|
56
87
|
) => boolean | Promise<boolean>;
|
|
57
88
|
|
|
89
|
+
export type DispatchMiddleware = (
|
|
90
|
+
sceneId: string,
|
|
91
|
+
action: string,
|
|
92
|
+
params: DispatchParams,
|
|
93
|
+
next: (sceneId: string, action: string, params: DispatchParams) => Promise<DispatchResult>,
|
|
94
|
+
) => Promise<DispatchResult>;
|
|
95
|
+
|
|
58
96
|
export default class DispatchCommandHandler {
|
|
59
97
|
private interceptors: NavigationInterceptor[] = [];
|
|
98
|
+
private systemMiddlewares: DispatchMiddleware[] = [];
|
|
60
99
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
100
|
+
addMiddleware(middleware: DispatchMiddleware) {
|
|
101
|
+
this.systemMiddlewares.push(middleware);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
removeMiddleware(middleware: DispatchMiddleware) {
|
|
105
|
+
this.systemMiddlewares = this.systemMiddlewares.filter(item => item !== middleware);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
interceptorMiddleware: DispatchMiddleware = async (sceneId, action, params, next) => {
|
|
66
109
|
const { from, to, props } = params;
|
|
67
110
|
const intercepted = await this.intercept(action, {
|
|
68
111
|
sceneId,
|
|
@@ -70,14 +113,66 @@ export default class DispatchCommandHandler {
|
|
|
70
113
|
to,
|
|
71
114
|
props,
|
|
72
115
|
});
|
|
73
|
-
|
|
74
116
|
if (intercepted) {
|
|
75
117
|
return { ok: false, code: 'intercepted' };
|
|
76
118
|
}
|
|
77
|
-
|
|
119
|
+
return next(sceneId, action, { ...params, [INTERCEPT_CHECKED_PROP]: true });
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
async dispatchRaw(
|
|
123
|
+
sceneId: string,
|
|
124
|
+
action: string,
|
|
125
|
+
params: DispatchParams,
|
|
126
|
+
): Promise<DispatchResult> {
|
|
127
|
+
if (!params[INTERCEPT_CHECKED_PROP]) {
|
|
128
|
+
const { from, to, props } = params;
|
|
129
|
+
const intercepted = await this.intercept(action, {
|
|
130
|
+
sceneId,
|
|
131
|
+
from,
|
|
132
|
+
to,
|
|
133
|
+
props,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
if (intercepted) {
|
|
137
|
+
return { ok: false, code: 'intercepted' };
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const nativeParams: DispatchParams = { ...params };
|
|
142
|
+
for (const key of INTERNAL_DISPATCH_PROPS) {
|
|
143
|
+
delete nativeParams[key];
|
|
144
|
+
}
|
|
145
|
+
if (nativeParams.result !== undefined) {
|
|
146
|
+
nativeParams.result = resultHandler.normalizePendingResult(nativeParams.result);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const wire = await NativeNavigation.dispatch(sceneId, action, nativeParams);
|
|
78
150
|
return normalizeDispatchResult(wire);
|
|
79
151
|
}
|
|
80
152
|
|
|
153
|
+
async dispatch(
|
|
154
|
+
sceneId: string,
|
|
155
|
+
action: string,
|
|
156
|
+
params: DispatchParams,
|
|
157
|
+
): Promise<DispatchResult> {
|
|
158
|
+
const chain = this.systemMiddlewares.slice();
|
|
159
|
+
const invoke = (
|
|
160
|
+
cursor: number,
|
|
161
|
+
currentSceneId: string,
|
|
162
|
+
currentAction: string,
|
|
163
|
+
currentParams: DispatchParams,
|
|
164
|
+
): Promise<DispatchResult> => {
|
|
165
|
+
if (cursor < chain.length) {
|
|
166
|
+
const middleware = chain[cursor];
|
|
167
|
+
return middleware(currentSceneId, currentAction, currentParams, (s, a, p) =>
|
|
168
|
+
invoke(cursor + 1, s, a, p),
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
return this.dispatchRaw(currentSceneId, currentAction, currentParams);
|
|
172
|
+
};
|
|
173
|
+
return invoke(0, sceneId, action, params);
|
|
174
|
+
}
|
|
175
|
+
|
|
81
176
|
private async intercept(action: string, params: InterceptParams): Promise<boolean> {
|
|
82
177
|
for (const interceptor of this.interceptors.slice()) {
|
|
83
178
|
const result = interceptor(action, params);
|
|
@@ -96,6 +191,10 @@ export default class DispatchCommandHandler {
|
|
|
96
191
|
removeInterceptor(interceptor: NavigationInterceptor) {
|
|
97
192
|
this.interceptors = this.interceptors.filter(item => item !== interceptor);
|
|
98
193
|
}
|
|
194
|
+
|
|
195
|
+
clearInterceptors() {
|
|
196
|
+
this.interceptors = [];
|
|
197
|
+
}
|
|
99
198
|
}
|
|
100
199
|
|
|
101
200
|
export const dispatchHandler = new DispatchCommandHandler();
|