8000 Make navigateTo return a promise · galaxyblur/nativescript-vue@9610865 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9610865

Browse files
committed
Make navigateTo return a promise
1 parent e21fc56 commit 9610865

File tree

3 files changed

+34
-31
lines changed

3 files changed

+34
-31
lines changed

platform/nativescript/navigator-plugin.js

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,37 @@ export default {
1919
return frame.goBack()
2020
}
2121
Vue.navigateTo = Vue.prototype.$navigateTo = function(component, options) {
22-
const placeholder = Vue.$document.createComment('placeholder')
22+
return new Promise(resolve => {
23+
const placeholder = Vue.$document.createComment('placeholder')
2324

24-
const contentComponent = Vue.extend(component)
25-
const vm = new contentComponent(options.context)
26-
vm.$mount(placeholder)
25+
const contentComponent = Vue.extend(component)
26+
const vm = new contentComponent(options.context)
27+
vm.$mount(placeholder)
2728

28-
const toPage = isPage(vm.$el) ? vm.$el.nativeView : new Page()
29+
const toPage = isPage(vm.$el) ? vm.$el.nativeView : new Page()
2930

30-
if (!isPage(vm.$el)) {
31-
toPage.content = vm.$el.nativeView
32-
}
33-
34-
toPage[VUE_VM_REF] = vm
31+
if (!isPage(vm.$el)) {
32+
toPage.content = vm.$el.nativeView
33+
}
3534

36-
const frame = topmost()
37-
const navigate = frame ? frame.navigate : start
38-
39-
navigate.call(
40-
frame,
41-
Object.assign(
42-
{
43-
create: () => toPage
44-
},
45-
options
35+
toPage[VUE_VM_REF] = vm
36+
37+
const frame = topmost()
38+
const navigate = frame ? frame.navigate : start
39+
40+
navigate.call(
41+
frame,
42+
Object.assign(
43+
{
44+
create: () => {
45+
resolve(toPage)
46+
return toPage
47+
}
48+
},
49+
options
50+
)
4651
)
47-
)
52+
})
4853
}
4954
}
5055
}

platform/nativescript/router-plugin.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ export default {
4444
this.$navigateTo(initial, {
4545
context: { router },
4646
clearHistory: true
47-
})
48-
49-
// Mount the root component (Should be <router-page>) to register router hooks
50-
this.$nextTick(() => {
51-
const placeholder = this.$document.createComment('placeholder')
47+
}).then(() => {
48+
// Mount the root component (Should be <router-page>) to register router hooks
49+
this.$nextTick(() => {
50+
const placeholder = this.$document.createComment('placeholder')
5251

53-
this.$mount(placeholder)
52+
this.$mount(placeholder)
53+
})
5454
})
5555
}
5656
}

platform/nativescript/runtime/components/router-page.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ export default {
1616
router.afterEach(({ matched }) => {
1717
const component = matched[0].components.default
1818

19-
parent.$nextTick(() => {
20-
parent.$navigateTo(component, {
21-
context: { router }
22-
})
19+
parent.$navigateTo(component, {
20+
context: { router }
2321
})
2422
})
2523

0 commit comments

Comments
 (0)
0