This repository has been archived by the owner on Jan 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
75 lines (64 loc) · 1.6 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import Router from './src/Router'
const SingletonRouter = {
router: null,
interceptors: [],
}
const navigationMethodFields = [
'push',
'pop',
'popToTop',
'replace',
'showModal',
'dismissModal',
]
const coreMethodFields = [
'config',
'setTitle',
'getCurrentRoute',
'getCurrentQuery',
'updateParams',
'updateTitle',
'subscribe',
'subscribe',
'unsubscribe',
'broadcast',
]
const propertyFields = ['routes']
navigationMethodFields.forEach((field) => {
SingletonRouter[field] = (...args) => {
const interceptorArgs = {
method: field,
args,
}
const interceptorResult = SingletonRouter.interceptors.reduce(
(previousResult, interceptor) => interceptor(previousResult),
interceptorArgs
)
return SingletonRouter.router[field](...interceptorResult.args)
}
})
coreMethodFields.forEach((field) => {
SingletonRouter[field] = (...args) => SingletonRouter.router[field](...args)
})
propertyFields.forEach((field) => {
Object.defineProperty(SingletonRouter, field, {
get() {
return SingletonRouter.router[field]
},
})
})
export {
NavigationStyles,
NavigationReducer,
createNavigationEnabledStore,
} from './src/Router'
export function createStackNavigation(initialRoute, routes, useMemoryHistory, defaultRouteConfig) {
if (!SingletonRouter.router) {
SingletonRouter.router = new Router(initialRoute, routes, useMemoryHistory, defaultRouteConfig)
}
return SingletonRouter.router.navigationProvider
}
export function addInterceptor(interceptor) {
SingletonRouter.interceptors.push(interceptor)
}
export default SingletonRouter