11var _ = require ( '../util' )
2+ var compile = require ( '../compile/compile' )
23var templateParser = require ( '../parse/template' )
4+ var transition = require ( '../transition' )
35
46module . exports = {
57
@@ -8,10 +10,16 @@ module.exports = {
810 if ( ! el . __vue__ ) {
911 this . ref = document . createComment ( 'v-if' )
1012 _ . replace ( el , this . ref )
11- this . inserted = false
12- if ( el . tagName === 'TEMPLATE' ) {
13- this . el = templateParser . parse ( el , true )
14- }
13+ this . isBlock = el . tagName === 'TEMPLATE'
14+ this . template = this . isBlock
15+ ? templateParser . parse ( el , true )
16+ : el
17+ // compile the nested partial
18+ this . linker = compile (
19+ this . template ,
20+ this . vm . $options ,
21+ true
22+ )
1523 } else {
1624 this . invalid = true
1725 _ . warn (
@@ -24,29 +32,42 @@ module.exports = {
2432 update : function ( value ) {
2533 if ( this . invalid ) return
2634 if ( value ) {
27- if ( ! this . inserted ) {
28- if ( ! this . childVM ) {
29- this . childVM = this . vm . $addChild ( {
30- el : this . el ,
31- data : this . vm . _data ,
32- inherit : true ,
33- _anonymous : true
34- } )
35+ this . insert ( )
36+ } else {
37+ this . unbind ( )
38+ }
39+ } ,
40+
41+ insert : function ( ) {
42+ var vm = this . vm
43+ var el = templateParser . clone ( this . template )
44+ var ref = this . ref
45+ var decompile = this . linker ( vm , el )
46+ if ( this . isBlock ) {
47+ var blockStart = el . firstChild
48+ this . decompile = function ( ) {
49+ decompile ( )
50+ var node = blockStart
51+ var next
52+ while ( node !== ref ) {
53+ next = node . nextSibling
54+ transition . remove ( node , vm )
55+ node = next
3556 }
36- this . childVM . $before ( this . ref )
37- this . inserted = true
3857 }
3958 } else {
40- if ( this . inserted ) {
41- this . childVM . $remove ( )
42- this . inserted = false
59+ this . decompile = function ( ) {
60+ decompile ( )
61+ transition . remove ( el , vm )
4362 }
4463 }
64+ transition . before ( el , ref , vm )
4565 } ,
4666
4767 unbind : function ( ) {
48- if ( this . childVM ) {
49- this . childVM . $destroy ( )
68+ if ( this . decompile ) {
69+ this . decompile ( )
70+ this . decompile = null
5071 }
5172 }
5273
0 commit comments