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 18@Retention({policy:"SOURCE"}) @interface memo_intrinsic {} 19@Retention({policy:"SOURCE"}) @interface memo_entry {} 20 21export declare function __context(): __memo_context_type 22export declare function __id(): __memo_id_type 23 24class Test { 25 @memo void_method(): void { 26 } 27 28 @memo string_method_with_return(arg: string): string { 29 return arg 30 } 31 32 @memo method_with_type_parameter<T>(arg: T): T { 33 return arg 34 } 35 36 @memo_intrinsic intrinsic_method(): int { 37 return 0 38 } 39 40 @memo_intrinsic intrinsic_method_with_this(): int { 41 this.void_method() 42 return 0 43 } 44 45 @memo_entry memoEntry<R>(__memo_context: __memo_context_type, __memo_id: __memo_id_type, @memo entry: () => R): R { 46 const getContext = () => { 47 return __context() 48 } 49 const getId = () => { 50 return __id() 51 } 52 { 53 const __memo_context = getContext() 54 const __memo_id = getId() 55 return entry() 56 } 57 } 58} 59 60class Use { 61 @memo test() { 62 const test = new Test() 63 64 test.string_method_with_return("a string") 65 test.method_with_type_parameter("I'm string") 66 } 67} 68