@@ -85,26 +85,28 @@ module.exports = {
8585
8686 bind : function ( ) {
8787
88- var self = this ,
89- el = self . el ,
90- ctn = self . container = el . parentNode
88+ var el = this . el ,
89+ ctn = this . container = el . parentNode
9190
9291 // extract child VM information, if any
9392 ViewModel = ViewModel || require ( '../viewmodel' )
94- self . Ctor = self . Ctor || ViewModel
95-
93+ this . Ctor = this . Ctor || ViewModel
9694 // extract transition information
97- self . hasTrans = el . hasAttribute ( config . attrs . transition )
95+ this . hasTrans = el . hasAttribute ( config . attrs . transition )
96+ // extract child Id, if any
97+ this . childId = utils . attr ( el , 'component-id' )
9898
9999 // create a comment node as a reference node for DOM insertions
100- self . ref = document . createComment ( config . prefix + '-repeat-' + self . key )
101- ctn . insertBefore ( self . ref , el )
100+ this . ref = document . createComment ( config . prefix + '-repeat-' + this . key )
101+ ctn . insertBefore ( this . ref , el )
102102 ctn . removeChild ( el )
103103
104- self . initiated = false
105- self . collection = null
106- self . vms = null
107- self . mutationListener = function ( path , arr , mutation ) {
104+ this . initiated = false
105+ this . collection = null
106+ this . vms = null
107+
108+ var self = this
109+ this . mutationListener = function ( path , arr , mutation ) {
108110 var method = mutation . method
109111 mutationHandlers [ method ] . call ( self , mutation )
110112 if ( method !== 'push' && method !== 'pop' ) {
@@ -119,31 +121,33 @@ module.exports = {
119121
120122 update : function ( collection , init ) {
121123
122- var self = this
123- self . unbind ( true )
124+ this . unbind ( true )
124125 // attach an object to container to hold handlers
125- self . container . vue_dHandlers = utils . hash ( )
126+ this . container . vue_dHandlers = utils . hash ( )
126127 // if initiating with an empty collection, we need to
127128 // force a compile so that we get all the bindings for
128129 // dependency extraction.
129- if ( ! self . initiated && ( ! collection || ! collection . length ) ) {
130- self . buildItem ( )
131- self . initiated = true
130+ if ( ! this . initiated && ( ! collection || ! collection . length ) ) {
131+ this . buildItem ( )
132+ this . initiated = true
133+ }
134+ collection = this . collection = collection || [ ]
135+ this . vms = [ ]
136+ if ( this . childId ) {
137+ this . vm . $ [ this . childId ] = this . vms
132138 }
133- collection = self . collection = collection || [ ]
134- self . vms = [ ]
135139
136140 // listen for collection mutation events
137141 // the collection has been augmented during Binding.set()
138142 if ( ! collection . __observer__ ) Observer . watchArray ( collection , null , new Emitter ( ) )
139- collection . __observer__ . on ( 'mutate' , self . mutationListener )
143+ collection . __observer__ . on ( 'mutate' , this . mutationListener )
140144
141145 // create child-vms and append to DOM
142146 if ( collection . length ) {
143147 for ( var i = 0 , l = collection . length ; i < l ; i ++ ) {
144- self . buildItem ( collection [ i ] , i )
148+ this . buildItem ( collection [ i ] , i )
145149 }
146- if ( ! init ) self . changed ( )
150+ if ( ! init ) this . changed ( )
147151 }
148152 } ,
149153
@@ -154,9 +158,9 @@ module.exports = {
154158 * Batched to ensure it's called only once every event loop.
155159 */
156160 changed : function ( ) {
161+ if ( this . queued ) return
162+ this . queued = true
157163 var self = this
158- if ( self . queued ) return
159- self . queued = true
160164 setTimeout ( function ( ) {
161165 self . compiler . parseDeps ( )
162166 self . queued = false
@@ -221,6 +225,9 @@ module.exports = {
221225 } ,
222226
223227 unbind : function ( ) {
228+ if ( this . childId ) {
229+ delete this . vm . $ [ this . childId ]
230+ }
224231 if ( this . collection ) {
225232 this . collection . __observer__ . off ( 'mutate' , this . mutationListener )
226233 var i = this . vms . length
0 commit comments