@@ -45,15 +45,14 @@ module.exports = {
45
45
// transition related state
46
46
this . pendingRemovals = 0
47
47
this . pendingRemovalCb = null
48
+ // check dynamic component params
49
+ // create a ref anchor
50
+ this . anchor = _ . createAnchor ( 'v-component' )
51
+ _ . replace ( this . el , this . anchor )
52
+ this . transMode = this . param ( 'transition-mode' )
48
53
// if static, build right now.
49
54
if ( this . literal ) {
50
- this . resolveComponent ( this . expression , _ . bind ( this . initStatic , this ) )
51
- } else {
52
- // check dynamic component params
53
- // create a ref anchor
54
- this . anchor = _ . createAnchor ( 'v-component' )
55
- _ . replace ( this . el , this . anchor )
56
- this . transMode = this . param ( 'transition-mode' )
55
+ this . setComponent ( this . expression )
57
56
}
58
57
} else {
59
58
process . env . NODE_ENV !== 'production' && _ . warn (
@@ -63,25 +62,6 @@ module.exports = {
63
62
}
64
63
} ,
65
64
66
- /**
67
- * Initialize a static component.
68
- */
69
-
70
- initStatic : function ( ) {
71
- var anchor = this . el
72
- var activateHook = this . Component . options . activate
73
- var child = this . childVM = this . build ( )
74
- if ( activateHook ) {
75
- activateHook . call ( child , insert )
76
- } else {
77
- insert ( )
78
- }
79
- function insert ( ) {
80
- child . $before ( anchor )
81
- _ . remove ( anchor )
82
- }
83
- } ,
84
-
85
65
/**
86
66
* Public update, called by the watcher in the dynamic
87
67
* literal scenario, e.g. <component :is="view">
@@ -114,22 +94,10 @@ module.exports = {
114
94
this . remove ( this . childVM , cb )
115
95
this . childVM = null
116
96
} else {
117
- this . resolveComponent ( value , _ . bind ( function ( ) {
118
- this . unbuild ( true )
119
- var self = this
120
- var activateHook = this . Component . options . activate
121
- var cached = this . getCached ( )
122
- var newComponent = this . build ( )
123
- if ( activateHook && ! cached ) {
124
- this . waitingFor = newComponent
125
- activateHook . call ( newComponent , function ( ) {
126
- self . waitingFor = null
127
- self . transition ( newComponent , cb )
128
- } )
129
- } else {
130
- this . transition ( newComponent , cb )
131
- }
132
- } , this ) )
97
+ var self = this
98
+ this . resolveComponent ( value , function ( ) {
99
+ self . mountComponent ( cb )
100
+ } )
133
101
}
134
102
} ,
135
103
@@ -147,6 +115,33 @@ module.exports = {
147
115
this . vm . _resolveComponent ( id , this . pendingComponentCb )
148
116
} ,
149
117
118
+ /**
119
+ * Create a new instance using the current constructor and
120
+ * replace the existing instance. This method doesn't care
121
+ * whether the new component and the old one are actually
122
+ * the same.
123
+ *
124
+ * @param {Function } [cb]
125
+ */
126
+
127
+ mountComponent : function ( cb ) {
128
+ // actual mount
129
+ this . unbuild ( true )
130
+ var self = this
131
+ var activateHook = this . Component . options . activate
132
+ var cached = this . getCached ( )
133
+ var newComponent = this . build ( )
134
+ if ( activateHook && ! cached ) {
135
+ this . waitingFor = newComponent
136
+ activateHook . call ( newComponent , function ( ) {
137
+ self . waitingFor = null
138
+ self . transition ( newComponent , cb )
139
+ } )
140
+ } else {
141
+ this . transition ( newComponent , cb )
142
+ }
143
+ } ,
144
+
150
145
/**
151
146
* When the component changes or unbinds before an async
152
147
* constructor is resolved, we need to invalidate its
0 commit comments