11var _ = require ( '../util' )
2- var Watcher = require ( '../watcher' )
32var templateParser = require ( '../parse/template' )
43
54module . exports = {
65
76 isLiteral : true ,
87
98 /**
10- * Setup. Need to check a few possible permutations :
9+ * Setup. Two possible usages :
1110 *
12- * - literal :
11+ * - static :
1312 * v-component="comp"
1413 *
1514 * - dynamic:
1615 * v-component="{{currentView}}"
17- *
18- * - conditional:
19- * v-component="comp" v-if="abc"
20- *
21- * - dynamic + conditional:
22- * v-component="{{currentView}}" v-if="abc"
2316 */
2417
2518 bind : function ( ) {
2619 if ( ! this . el . __vue__ ) {
2720 // create a ref anchor
2821 this . ref = document . createComment ( 'v-component' )
2922 _ . replace ( this . el , this . ref )
30- // check v-if conditionals
31- this . checkIf ( )
3223 // check keep-alive options
3324 this . checkKeepAlive ( )
3425 // if static, build right now.
@@ -44,46 +35,6 @@ module.exports = {
4435 }
4536 } ,
4637
47- /**
48- * Check if v-component is being used together with v-if.
49- * If yes, we created a watcher for the v-if value and
50- * react to its value change in `this.ifCallback`.
51- */
52-
53- checkIf : function ( ) {
54- var condition = _ . attr ( this . el , 'if' )
55- if ( condition !== null ) {
56- var self = this
57- this . ifWatcher = new Watcher (
58- this . vm ,
59- condition ,
60- function ( value ) {
61- self . toggleIf ( value )
62- }
63- )
64- this . active = this . ifWatcher . value
65- } else {
66- this . active = true
67- }
68- } ,
69-
70- /**
71- * Callback when v-if value changes.
72- * Marks the active flag.
73- *
74- * @param {* } value
75- */
76-
77- toggleIf : function ( value ) {
78- if ( value ) {
79- this . active = true
80- this . build ( )
81- } else {
82- this . active = false
83- this . unbuild ( true )
84- }
85- } ,
86-
8738 /**
8839 * Check if the "keep-alive" flag is present.
8940 * If yes, instead of destroying the active vm when
@@ -119,9 +70,6 @@ module.exports = {
11970 */
12071
12172 build : function ( ) {
122- if ( ! this . active ) {
123- return
124- }
12573 if ( this . keepAlive ) {
12674 var vm = this . cache [ this . ctorId ]
12775 if ( vm ) {
@@ -178,16 +126,12 @@ module.exports = {
178126 /**
179127 * Unbind.
180128 * Make sure keepAlive is set to false so that the
181- * instance is always destroyed. Teardown v-if watcher
182- * if present.
129+ * instance is always destroyed.
183130 */
184131
185132 unbind : function ( ) {
186133 this . keepAlive = false
187134 this . unbuild ( )
188- if ( this . ifWatcher ) {
189- this . ifWatcher . teardown ( )
190- }
191135 }
192136
193137}
0 commit comments