Procházet zdrojové kódy

still need to check conversion in v-repeat update

Evan You před 12 roky
rodič
revize
5fb9f24176
2 změnil soubory, kde provedl 8 přidání a 6 odebrání
  1. 5 3
      src/directives/repeat.js
  2. 3 3
      src/observer.js

+ 5 - 3
src/directives/repeat.js

@@ -140,8 +140,12 @@ module.exports = {
             this.vm.$[this.childId] = this.vms
         }
 
+        // If the collection is not already converted for observation,
+        // we need to convert and watch it.
+        if (!Observer.convert(collection)) {
+            Observer.watch(collection)
+        }
         // listen for collection mutation events
-        // the collection has been augmented during Binding.set()
         collection.__emitter__.on('mutate', this.mutationListener)
 
         // create new VMs and append to DOM
@@ -397,8 +401,6 @@ function objectToArray (obj) {
         def(data, '$key', key)
         res.push(data)
     }
-    Observer.convert(res)
-    Observer.watch(res)
     return res
 }
 

+ 3 - 3
src/observer.js

@@ -178,7 +178,7 @@ function isWatchable (obj) {
  *  Convert an Object/Array to give it a change emitter.
  */
 function convert (obj) {
-    if (obj.__emitter__) return false
+    if (obj.__emitter__) return true
     var emitter = new Emitter()
     def(obj, '__emitter__', emitter)
     emitter.on('set', function () {
@@ -190,7 +190,7 @@ function convert (obj) {
     })
     emitter.values = utils.hash()
     emitter.owners = []
-    return true
+    return false
 }
 
 /**
@@ -358,7 +358,7 @@ function observe (obj, rawPath, observer) {
     if (!isWatchable(obj)) return
 
     var path = rawPath ? rawPath + '.' : '',
-        alreadyConverted = !convert(obj),
+        alreadyConverted = convert(obj),
         emitter = obj.__emitter__
 
     // setup proxy listeners on the parent observer.