1/* 2 * Copyright (C) 2025 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 16import { memo, __memo_context_type, __memo_id_type } from "@ohos.arkui.stateManagement" 17 18export declare function __context(): __memo_context_type 19export declare function __id(): __memo_id_type 20type MemoType = @memo () => void 21 22class Test { 23 @memo void_method(): void { 24 } 25 26 @memo internal_call() { 27 this.void_method() 28 } 29 30 @memo method_with_internals() { 31 __context() 32 __id() 33 } 34 35 memo_lambda() { 36 @memo () => { 37 38 } 39 } 40 41 @memo memo_variables() { 42 @memo const f = (): number => { 43 return 123 44 }, g = (x: number): number => { 45 return 123 + x 46 } 47 48 const h = @memo (): number => { 49 return 1 50 } 51 52 f() 53 g(1) 54 h() 55 } 56 57 @memo args_with_default_values( 58 arg1: int = 10, 59 arg2: () => int = () => { return 20 }, 60 arg3: int = arg1, 61 arg4?: int 62 ): void { 63 console.log(arg1, arg2, arg3, arg4) 64 console.log(arg2()) 65 } 66 67 @memo optional_args( 68 arg1?: int, 69 arg2?: () => int 70 ) { 71 console.log(arg1) 72 console.log(arg2) 73 console.log(arg2?.()) 74 } 75 76 @memo type_alias( 77 arg: MemoType 78 ) { 79 arg() 80 } 81}