Skip to content

Commit d2fc21e

Browse files
committed
adjust component internals for vue-router
1 parent 04cf141 commit d2fc21e

File tree

1 file changed

+48
-31
lines changed

1 file changed

+48
-31
lines changed

src/directives/component.js

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,49 @@ module.exports = {
6060
}
6161
},
6262

63+
/**
64+
* Public update, called by the watcher in the dynamic
65+
* literal scenario, e.g. v-component="{{view}}"
66+
*/
67+
68+
update: function (value) {
69+
this.realUpdate(value)
70+
},
71+
72+
/**
73+
* Switch dynamic components. May resolve the component
74+
* asynchronously, and perform transition based on
75+
* specified transition mode. Accepts an async callback
76+
* which is called when the transition ends. (This is
77+
* exposed for vue-router)
78+
*
79+
* @param {String} value
80+
* @param {Function} [cb]
81+
*/
82+
83+
realUpdate: function (value, cb) {
84+
this.invalidatePending()
85+
if (!value) {
86+
// just remove current
87+
this.unbuild()
88+
this.remove(this.childVM, cb)
89+
this.unsetCurrent()
90+
} else {
91+
this.resolveCtor(value, _.bind(function () {
92+
this.unbuild()
93+
var newComponent = this.build()
94+
var self = this
95+
if (this.readyEvent) {
96+
newComponent.$once(this.readyEvent, function () {
97+
self.swapTo(newComponent, cb)
98+
})
99+
} else {
100+
this.swapTo(newComponent, cb)
101+
}
102+
}, this))
103+
}
104+
},
105+
63106
/**
64107
* Resolve the component constructor to use when creating
65108
* the child vm.
@@ -156,59 +199,33 @@ module.exports = {
156199
}
157200
},
158201

159-
/**
160-
* Update callback for the dynamic literal scenario,
161-
* e.g. v-component="{{view}}"
162-
*/
163-
164-
update: function (value) {
165-
this.invalidatePending()
166-
if (!value) {
167-
// just remove current
168-
this.remove(this.childVM)
169-
this.unsetCurrent()
170-
} else {
171-
this.resolveCtor(value, _.bind(function () {
172-
this.unbuild()
173-
var newComponent = this.build()
174-
var self = this
175-
if (this.readyEvent) {
176-
newComponent.$once(this.readyEvent, function () {
177-
self.swapTo(newComponent)
178-
})
179-
} else {
180-
this.swapTo(newComponent)
181-
}
182-
}, this))
183-
}
184-
},
185-
186202
/**
187203
* Actually swap the components, depending on the
188204
* transition mode. Defaults to simultaneous.
189205
*
190206
* @param {Vue} target
207+
* @param {Function} [cb]
191208
*/
192209

193-
swapTo: function (target) {
210+
swapTo: function (target, cb) {
194211
var self = this
195212
var current = this.childVM
196213
this.unsetCurrent()
197214
this.setCurrent(target)
198215
switch (self.transMode) {
199216
case 'in-out':
200217
target.$before(self.ref, function () {
201-
self.remove(current)
218+
self.remove(current, cb)
202219
})
203220
break
204221
case 'out-in':
205222
self.remove(current, function () {
206-
target.$before(self.ref)
223+
target.$before(self.ref, cb)
207224
})
208225
break
209226
default:
210227
self.remove(current)
211-
target.$before(self.ref)
228+
target.$before(self.ref, cb)
212229
}
213230
},
214231

0 commit comments

Comments
 (0)