1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 * 15 * * RecycleManager - Recycle cache manager 16 * 17* all definitions in this file are framework internal 18*/ 19 20/** 21 * @class RecycleManager 22 * @description manage the JS object cached of current node 23 */ 24class RecycleManager { 25 // key: recycle node name 26 // value: recycle node JS object 27 private cachedRecycleNodes: Map<string, Array<ViewPU>> = undefined 28 29 constructor() { 30 this.cachedRecycleNodes = new Map<string, Array<ViewPU>>(); 31 } 32 33 public pushRecycleNode(name: string, node: ViewPU): void { 34 if (!this.cachedRecycleNodes.get(name)) { 35 this.cachedRecycleNodes.set(name, new Array<ViewPU>()); 36 } 37 this.cachedRecycleNodes.get(name)?.push(node); 38 } 39 40 public popRecycleNode(name: string): ViewPU { 41 return this.cachedRecycleNodes.get(name)?.pop(); 42 } 43 44 // When parent JS View is deleted, release all cached nodes 45 public purgeAllCachedRecycleNode(): void { 46 this.cachedRecycleNodes.forEach((nodes, _) => { 47 nodes.forEach((node) => { 48 node.resetRecycleCustomNode(); 49 }) 50 }) 51 this.cachedRecycleNodes.clear(); 52 } 53} 54