refactor(keep-alive): use property initializer

This commit is contained in:
Evan You 2018-09-27 10:19:36 -04:00
parent 1cc7734c24
commit 86d95cf33b

View 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