forked from vuejs/router
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mount.ts
39 lines (33 loc) · 975 Bytes
/
mount.ts
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
import { reactive, nextTick, ComputedRef, computed, shallowRef } from 'vue'
import { RouteLocationNormalizedLoose } from './utils'
import {
routeLocationKey,
routerViewLocationKey,
} from '../src/injectionSymbols'
export function createMockedRoute(initialValue: RouteLocationNormalizedLoose) {
const route = {} as {
[k in keyof RouteLocationNormalizedLoose]: ComputedRef<
RouteLocationNormalizedLoose[k]
>
}
const routeRef = shallowRef(initialValue)
function set(newRoute: RouteLocationNormalizedLoose) {
routeRef.value = newRoute
return nextTick()
}
for (let key in initialValue) {
// @ts-ignore
route[key] =
// new line to still get errors here
computed(() => routeRef.value[key as keyof RouteLocationNormalizedLoose])
}
const value = reactive(route)
return {
value,
set,
provides: {
[routeLocationKey as symbol]: value,
[routerViewLocationKey as symbol]: routeRef,
},
}
}