@@ -85,26 +85,28 @@ module.exports = {
85
85
86
86
bind : function ( ) {
87
87
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
91
90
92
91
// extract child VM information, if any
93
92
ViewModel = ViewModel || require ( '../viewmodel' )
94
- self . Ctor = self . Ctor || ViewModel
95
-
93
+ this . Ctor = this . Ctor || ViewModel
96
94
// 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' )
98
98
99
99
// 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 )
102
102
ctn . removeChild ( el )
103
103
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 ) {
108
110
var method = mutation . method
109
111
mutationHandlers [ method ] . call ( self , mutation )
110
112
if ( method !== 'push' && method !== 'pop' ) {
@@ -119,31 +121,33 @@ module.exports = {
119
121
120
122
update : function ( collection , init ) {
121
123
122
- var self = this
123
- self . unbind ( true )
124
+ this . unbind ( true )
124
125
// attach an object to container to hold handlers
125
- self . container . vue_dHandlers = utils . hash ( )
126
+ this . container . vue_dHandlers = utils . hash ( )
126
127
// if initiating with an empty collection, we need to
127
128
// force a compile so that we get all the bindings for
128
129
// 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
132
138
}
133
- collection = self . collection = collection || [ ]
134
- self . vms = [ ]
135
139
136
140
// listen for collection mutation events
137
141
// the collection has been augmented during Binding.set()
138
142
if ( ! collection . __observer__ ) Observer . watchArray ( collection , null , new Emitter ( ) )
139
- collection . __observer__ . on ( 'mutate' , self . mutationListener )
143
+ collection . __observer__ . on ( 'mutate' , this . mutationListener )
140
144
141
145
// create child-vms and append to DOM
142
146
if ( collection . length ) {
143
147
for ( var i = 0 , l = collection . length ; i < l ; i ++ ) {
144
- self . buildItem ( collection [ i ] , i )
148
+ this . buildItem ( collection [ i ] , i )
145
149
}
146
- if ( ! init ) self . changed ( )
150
+ if ( ! init ) this . changed ( )
147
151
}
148
152
} ,
149
153
@@ -154,9 +158,9 @@ module.exports = {
154
158
* Batched to ensure it's called only once every event loop.
155
159
*/
156
160
changed : function ( ) {
161
+ if ( this . queued ) return
162
+ this . queued = true
157
163
var self = this
158
- if ( self . queued ) return
159
- self . queued = true
160
164
setTimeout ( function ( ) {
161
165
self . compiler . parseDeps ( )
162
166
self . queued = false
@@ -221,6 +225,9 @@ module.exports = {
221
225
} ,
222
226
223
227
unbind : function ( ) {
228
+ if ( this . childId ) {
229
+ delete this . vm . $ [ this . childId ]
230
+ }
224
231
if ( this . collection ) {
225
232
this . collection . __observer__ . off ( 'mutate' , this . mutationListener )
226
233
var i = this . vms . length
0 commit comments