From 86d95cf33bcbd1b4dac9bad869a0fe33e8f067d3 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 27 Sep 2018 10:19:36 -0400 Subject: [PATCH] refactor(keep-alive): use property initializer --- packages/core/src/optional/keepAlive.ts | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/packages/core/src/optional/keepAlive.ts b/packages/core/src/optional/keepAlive.ts index 29386e7c..bd5e3355 100644 --- a/packages/core/src/optional/keepAlive.ts +++ b/packages/core/src/optional/keepAlive.ts @@ -16,19 +16,12 @@ type Cache = Map export const KeepAliveSymbol = Symbol() export class KeepAlive extends Component<{}, KeepAliveProps> { - cache: Cache - keys: Set + cache: Cache = new Map() + keys: Set = 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