Skip to content

Commit 0f39da6

Browse files
committed
refactor: clean up unneded code
1 parent 4738789 commit 0f39da6

File tree

3 files changed

+16
-158
lines changed

3 files changed

+16
-158
lines changed

platform/nativescript/plugins/router-plugin.js

Lines changed: 6 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
//import { before } from '../util/index'
2-
//import { Page } from 'tns-core-modules/ui/page'
31
import { android } from 'tns-core-modules/application'
42
import { isPlainObject } from 'shared/util'
53

64
const properties = ['stack', 'index', 'current']
75

86
class NativeScriptHistory {
9-
constructor(router, history, VueInstance) {
7+
constructor(router, history) {
108
this.router = router
119
this.history = history
1210
this.isGoingBack = false
13-
this._Vue = VueInstance
1411

1512
if (android) {
1613
android.on('activityBackPressed', function(args) {
@@ -48,14 +45,14 @@ class NativeScriptHistory {
4845
}
4946

5047
push(...args) {
51-
({ args, entry: this.currentEntry } = this._buildEntry(args))
48+
;({ args, entry: this.currentEntry } = this._buildEntry(args))
5249

5350
this.isGoingBack = false
5451
this.history.push.call(this.history, ...args)
5552
}
5653

5754
replace(...args) {
58-
({ args, entry: this.currentEntry } = this._buildEntry(args))
55+
;({ args, entry: this.currentEntry } = this._buildEntry(args))
5956

6057
this.isGoingBack = false
6158
this.history.replace.call(this.history, ...args)
@@ -102,14 +99,14 @@ class NativeScriptHistory {
10299
}
103100
}
104101

105-
export function patchDefaultRouter(router, Vue) {
102+
export function patchDefaultRouter(router) {
106103
if (router.__patched_for_routing__) {
107104
return
108105
}
109106

110107
router.__patched_for_routing__ = true
111108

112-
router.history = new NativeScriptHistory(router, router.history, Vue)
109+
router.history = new NativeScriptHistory(router, router.history)
113110

114111
router.push = function push(...args) {
115112
this.history.push(...args)
@@ -132,104 +129,6 @@ export function patchDefaultRouter(router, Vue) {
132129
}
133130
}
134131

135-
//export function patchRouter(router, Vue) {
136-
// if (router.__patched_for_page_routing__) {
137-
// return
138-
// }
139-
// router.__patched_for_page_routing__ = true
140-
//
141-
// // The problem: When using router.replace() to set the initial route
142-
// // the history index stays -1, which then causes an issue when visiting a route,
143-
// // going back, and then trying to visit again (the active route is not changed on nav back)
144-
// // This fixes it, since it allows the router.go logic to run
145-
// router.history.index = 0
146-
//
147-
// // initial navigation states
148-
// router.isBackNavigation = false
149-
// router.shouldNavigate = true
150-
// router.pageStack = []
151-
// router.pageTransition = null
152-
//
153-
// router.setPageTransition = (transition, duration, curve) => {
154-
// if (typeof transition === 'string') {
155-
// return (router.pageTransition = {
156-
// name: transition,
157-
// duration,
158-
// curve
159-
// })
160-
// }
161-
//
162-
// router.pageTransition = transition
163-
// }
164-
//
165-
// router._beginBackNavigation = (shouldNavigate = true) => {
166-
// if (router.isBackNavigation) {
167-
// throw new Error(
168-
// 'router._beginBackNavigation was called while already navigating back.'
169-
// )
170-
// }
171-
//
172-
// router.isBackNavigation = true
173-
// router.shouldNavigate = shouldNavigate
174-
// }
175-
//
176-
// router._finishBackNavigation = () => {
177-
// if (!router.isBackNavigation) {
178-
// throw new Error(
179-
// 'router._finishBackNavigation was called while there was no back navigation.'
180-
// )
181-
// }
182-
//
183-
// router.isBackNavigation = false
184-
// }
185-
//
186-
// router.go = before(router.go, router, n => {
187-
// if (n === -1 && !router.isBackNavigation) {
188-
// router._beginBackNavigation()
189-
// }
190-
// })
191-
//
192-
// router.afterEach(() => {
193-
// if (router.isBackNavigation) {
194-
// if (router.shouldNavigate) {
195-
// Vue.navigateBack()
196-
// }
197-
// router.pageStack.pop()
198-
// const page = router.pageStack[router.pageStack.length - 1]
199-
//
200-
// const callback = ({ isBackNavigation }) => {
201-
// if (isBackNavigation) {
202-
// router._finishBackNavigation()
203-
// }
204-
// page.off(Page.navigatedToEvent, callback)
205-
// }
206-
//
207-
// page.on(Page.navigatedToEvent, callback)
208-
//
209-
// return
210-
// }
211-
//
212-
// const component = router.getMatchedComponents()[0]
213-
//
214-
// router.app
215-
// .$navigateTo(component, {
216-
// context: { router },
217-
// transition: router.pageTransition
218-
// // Todo: add transitionAndroid and transitionIOS
219-
// })
220-
// .then(page => {
221-
// router.pageStack.push(page)
222-
//
223-
// page.on(Page.navigatedFromEvent, ({ isBackNavigation }) => {
224-
// if (isBackNavigation && !router.isBackNavigation) {
225-
// router._beginBackNavigation(false)
226-
// router.back()
227-
// }
228-
// })
229-
// })
230-
// })
231-
//}
232-
233132
export default {
234133
install(Vue) {
235134
Vue.mixin({
@@ -239,41 +138,7 @@ export default {
239138
return
240139
}
241140

242-
const router = this.$options.router
243-
//const isPageRouting = router.options.pageRouting
244-
//const self = this
245-
246-
//if (isPageRouting) {
247-
// patchRouter(router, Vue)
248-
//} else {
249-
patchDefaultRouter(router, Vue)
250-
251-
// return
252-
//}
253-
//
254-
//// Overwrite the default $start function
255-
//this.$start = () => {
256-
// this.__is_root__ = true
257-
// this.__started__ = true // skips the default start procedure
258-
// this.$options.render = () => {} // removes warning for no render / template
259-
//
260-
// // Mount the root component
261-
// const placeholder = Vue.$document.createComment('placeholder')
262-
// self.$mount(placeholder)
263-
//
264-
// const initial = router.getMatchedComponents()[0]
265-
//
266-
// this.$navigateTo(
267-
// initial,
268-
// {
269-
// context: { router },
270-
// clearHistory: true
271-
// },
272-
// page => {
273-
// router.pageStack.push(page)
274-
// }
275-
// )
276-
//}
141+
patchDefaultRouter(this.$options.router)
277142
}
278143
})
279144
}

platform/nativescript/runtime/components/frame.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { setFrame, getFrame, deleteFrame } from '../../util/frame'
2-
import { PAGE_REF } from './page'
32
import { extend } from 'shared/util'
43
import { ios } from 'tns-core-modules/application'
54

65
let idCounter = 1
76

87
const propMap = {
9-
'transition': 'transition',
8+
transition: 'transition',
109
'ios:transition': 'transitioniOS',
1110
'android:transition': 'transitionAndroid'
1211
}
@@ -54,20 +53,13 @@ export default {
5453
deleteFrame(this.properties.id)
5554
},
5655
render(h) {
57-
let vnode = this.$slots.default
58-
59-
if (this.hasRouterView && this.isBackNavigation) {
60-
this.isBackNavigation = false
61-
vnode = this.$el.nativeView.currentPage[PAGE_REF] || vnode
62-
}
63-
6456
return h(
6557
'NativeFrame',
6658
{
6759
attrs: this.properties,
6860
on: this.$listeners
6961
},
70-
vnode
62+
this.$slots.default
7163
)
7264
},
7365
methods: {
@@ -98,7 +90,7 @@ export default {
9890
notifyPageMounted(pageVm) {
9991
this.$nextTick(_ =>
10092
this.navigate({
101-
create: _ => pageVm.$el.nativeView
93+
create: () => pageVm.$el.nativeView
10294
})
10395
)
10496
},
@@ -109,11 +101,6 @@ export default {
109101
},
110102

111103
navigate(entry, back = this.isGoingBack) {
112-
if (this.isBackNavigation) {
113-
console.log('skipping navigate()')
114-
return
115-
}
116-
117104
const frame = this._getFrame()
118105

119106
if (back || (ios && this.isGoingBack === undefined)) {

platform/nativescript/runtime/components/page.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ export default {
1313
)
1414
},
1515
created() {
16-
this.$vnode.parent.data.keepAlive = true
16+
if (this.$router) {
17+
this.$vnode.parent.data.keepAlive = true
18+
}
1719
},
1820
mounted() {
1921
this.$el.nativeView[PAGE_REF] = this
@@ -28,6 +30,10 @@ export default {
2830
if (e.isBackNavigation) {
2931
this.$el.nativeView.off('navigatedFrom', handler)
3032

33+
if (!this.$router) {
34+
return this.$parent.$destroy()
35+
}
36+
3137
if (ios) {
3238
this._findParentFrame().isGoingBack = undefined
3339
const history = this.$router.history.history

0 commit comments

Comments
 (0)