]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor(keep-alive): use property initializer
authorEvan You <yyx990803@gmail.com>
Thu, 27 Sep 2018 14:19:36 +0000 (10:19 -0400)
committerEvan You <yyx990803@gmail.com>
Thu, 27 Sep 2018 14:19:36 +0000 (10:19 -0400)
packages/core/src/optional/keepAlive.ts

index 29386e7c32dd546fe4c5706eae077459e4e8c748..bd5e33557e194a1fbfcdf05c2e65f38c957df7b8 100644 (file)
@@ -16,19 +16,12 @@ type Cache = Map<CacheKey, VNode>
 export const KeepAliveSymbol = Symbol()
 
 export class KeepAlive extends Component<{}, KeepAliveProps> {
-  cache: Cache
-  keys: Set<CacheKey>
+  cache: Cache = new Map()
+  keys: Set<CacheKey> = new Set()
 
   // to be set in createRenderer when instance is created
   $unmount: (instance: MountedComponent) => void
 
-  created() {
-    this.cache = new Map()
-    // keys represents the "freshness" of cached components
-    // oldest cached ones will be pruned first when cache count exceeds max
-    this.keys = new Set()
-  }
-
   beforeUnmount() {
     this.cache.forEach(vnode => {
       // change flag so it can be properly unmounted