Просмотр исходного кода

just use cid as keep-alive key

Evan You 10 лет назад
Родитель
Сommit
cef5fea7d6
2 измененных файлов с 8 добавлено и 10 удалено
  1. 4 6
      src/directives/component.js
  2. 4 4
      test/unit/specs/async_component_spec.js

+ 4 - 6
src/directives/component.js

@@ -41,7 +41,6 @@ module.exports = {
       }
       // component resolution related state
       this.pendingComponentCb =
-      this.componentID =
       this.Component = null
       // transition related state
       this.pendingRemovals = 0
@@ -145,9 +144,8 @@ module.exports = {
 
   resolveComponent: function (id, cb) {
     var self = this
-    this.pendingComponentCb = _.cancellable(function (component) {
-      self.componentID = id
-      self.Component = component
+    this.pendingComponentCb = _.cancellable(function (Component) {
+      self.Component = Component
       cb()
     })
     this.vm._resolveComponent(id, this.pendingComponentCb)
@@ -177,7 +175,7 @@ module.exports = {
 
   build: function (extraOptions) {
     if (this.keepAlive) {
-      var cached = this.cache[this.componentID]
+      var cached = this.cache[this.Component.cid]
       if (cached) {
         return cached
       }
@@ -201,7 +199,7 @@ module.exports = {
       var parent = this._host || this.vm
       var child = parent.$addChild(options, this.Component)
       if (this.keepAlive) {
-        this.cache[this.componentID] = child
+        this.cache[this.Component.cid] = child
       }
       return child
     }

+ 4 - 4
test/unit/specs/async_component_spec.js

@@ -111,8 +111,8 @@ describe('Async components', function () {
       vm.view = 'view-b'
       function step1 () {
         // called after A resolves, but A should have been
-        // invalidated so not cotrId should be set
-        expect(vm._directives[0].componentID).toBe(null)
+        // invalidated so no Ctor should be set
+        expect(vm._directives[0].Component).toBe(null)
       }
       function step2 () {
         // B should resolve successfully
@@ -145,8 +145,8 @@ describe('Async components', function () {
       vm.$destroy()
       function next () {
         // called after A resolves, but A should have been
-        // invalidated so not cotrId should be set
-        expect(dir.componentID).toBe(null)
+        // invalidated so no Ctor should be set
+        expect(dir.Component).toBe(null)
         done()
       }
     })