@@ -36,6 +36,8 @@ module.exports = {
36
36
// extract inline template as a DocumentFragment
37
37
this . template = _ . extractContent ( this . el , true )
38
38
}
39
+ // pending callback for async component resolution
40
+ this . _pendingCb = null
39
41
// if static, build right now.
40
42
if ( ! this . _isDynamicLiteral ) {
41
43
this . resolveCtor ( this . expression , _ . bind ( function ( ) {
@@ -63,13 +65,27 @@ module.exports = {
63
65
64
66
resolveCtor : function ( id , cb ) {
65
67
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
+ }
73
89
} ,
74
90
75
91
/**
@@ -144,9 +160,9 @@ module.exports = {
144
160
*/
145
161
146
162
update : function ( value ) {
163
+ this . invalidatePending ( )
147
164
if ( ! value ) {
148
165
// just remove current
149
- this . unbuild ( )
150
166
this . remove ( this . childVM )
151
167
this . unsetCurrent ( )
152
168
} else {
@@ -224,6 +240,7 @@ module.exports = {
224
240
*/
225
241
226
242
unbind : function ( ) {
243
+ this . invalidatePending ( )
227
244
this . unbuild ( )
228
245
// destroy all keep-alive cached instances
229
246
if ( this . cache ) {
0 commit comments