8000 invalid pending async component callbacks · Snoopbobb/vue@da9eba3 · GitHub
[go: up one dir, main page]

Skip to content

Commit da9eba3

Browse files
committed
invalid pending async component callbacks
1 parent 4092246 commit da9eba3

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

src/directives/component.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ module.exports = {
3636
// extract inline template as a DocumentFragment
3737
this.template = _.extractContent(this.el, true)
3838
}
39+
// pending callback for async component resolution
40+
this._pendingCb = null
3941
// if static, build right now.
4042
if (!this._isDynamicLiteral) {
4143
this.resolveCtor(this.expression, _.bind(function () {
@@ -63,13 +65,27 @@ module.exports = {
6365

6466
resolveCtor: function (id, cb) {
6567
var self = this
66-
// TODO handle update/teardown before the component
67-
// is actually resolved
68-
this.vm._resolveComponent(id, function (ctor) {
69-
self.ctorId = id
70-
self.Ctor = ctor
71-
cb()
72-
})
68+
var pendingCb = this._pendingCb = function (ctor) {
69+
if (!pendingCb.invalidated) {
70+
self.ctorId = id
71+
self.Ctor = ctor
72+
cb()
73+
}
74+
}
75+
this.vm._resolveComponent(id, pendingCb)
76+
},
77+
78+
/**
79+
* When the component changes or unbinds before an async
80+
* constructor is resolved, we need to invalidate its
81+
* pending callback.
82+
*/
83+
84+
invalidatePending: function () {
85+
if (this._pendingCb) {
86+
this._pendingCb.invalidated = true
87+
this._pendingCb = null
88+
}
7389
},
7490

7591
/**
@@ -144,9 +160,9 @@ module.exports = {
144160
*/
145161

146162
update: function (value) {
163+
this.invalidatePending()
147164
if (!value) {
148165
// just remove current
149-
this.unbuild()
150166
this.remove(this.childVM)
151167
this.unsetCurrent()
152168
} else {
@@ -224,6 +240,7 @@ module.exports = {
224240
*/
225241

226242
unbind: function () {
243+
this.invalidatePending()
227244
this.unbuild()
228245
// destroy all keep-alive cached instances
229246
if (this.cache) {

src/instance/misc.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ exports._applyFilter = function (id, args) {
1717
return (filter.read || filter).apply(this, args)
1818
}
1919

20+
/**
21+
* Resolve a component, depending on whether the component
22+
* is defined normally or using an async factory function.
23+
* Resolves synchronously if already resolved, otherwise
24+
* resolves asynchronously and replaces the factory with
25+
* the resolved component.
26+
*
27+
* @param {String} id
28+
* @param {Function} cb
29+
*/
30+
2031
exports._resolveComponent = function (id, cb) {
2132
var registry = this.$options.components
2233
var raw = registry[id]

0 commit comments

Comments
 (0)
0