diff --git a/arkoala-arkts/arkui/src/ForEach.ts b/arkoala-arkts/arkui/src/ForEach.ts index a7b27089b6345d686499d5c4bcda768a95cd196d..7fea31af1bdadc6da449e11311e2771ccc712ff7 100644 --- a/arkoala-arkts/arkui/src/ForEach.ts +++ b/arkoala-arkts/arkui/src/ForEach.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -26,5 +26,5 @@ export function ForEach(data: Array, ) { RepeatByArray(data, (element: T, index: int32) => keyGenerator ? hashCodeFromString(keyGenerator!(element, (index as number))) : index, - (element: T, index: int32) => itemGenerator(element, (index as number))) + (element: T, index: int32) => { itemGenerator(element, (index as number)) }) } diff --git a/arkoala-arkts/arkui/src/LazyForEach.ts b/arkoala-arkts/arkui/src/LazyForEach.ts index 045a076c52198c1be89a0ff34b7514721ab7f61e..d9bd4023d1b29b8e1bfe975b985de988f34d0a29 100644 --- a/arkoala-arkts/arkui/src/LazyForEach.ts +++ b/arkoala-arkts/arkui/src/LazyForEach.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -138,7 +138,7 @@ export function LazyForEach(dataSource: IDataSource, memoEntry2( __context(), generator(element, index), - (element: T, index: number): void => itemGenerator(element, index), + (element: T, index: number): void => { itemGenerator(element, index) }, element, index ) diff --git a/arkoala/arkui/src/ForEach.ts b/arkoala/arkui/src/ForEach.ts index db9b600dad5d9f0bc4e66d4861ce3a694f4f8cb1..54e23ea6b8a309eba29893b19219f3fc85bfb876 100644 --- a/arkoala/arkui/src/ForEach.ts +++ b/arkoala/arkui/src/ForEach.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -24,5 +24,5 @@ export function ForEach(data: Array, ) { RepeatByArray(data, (element, index) => keyGenerator ? hashCodeFromString(keyGenerator(element, index)) : index, - (element, index) => itemGenerator(element, index)) -} \ No newline at end of file + (element, index) => { itemGenerator(element, index) }) +} diff --git a/arkoala/arkui/src/LazyForEach.ts b/arkoala/arkui/src/LazyForEach.ts index 526e3e1fec60d744646fe31f46e3f5c9c917931e..b4434c4976eeaf46a76a3f8111a4be006644f654 100644 --- a/arkoala/arkui/src/LazyForEach.ts +++ b/arkoala/arkui/src/LazyForEach.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -132,7 +132,7 @@ export function LazyForEach(dataSource: IDataSource, memoEntry2( __context(), generator(element, index), - (element: any, index: number): void => itemGenerator(element, index), + (element: any, index: number): void => { itemGenerator(element, index) }, element, index ) diff --git a/incremental/runtime/src/memo/bind.ts b/incremental/runtime/src/memo/bind.ts index c74f8ef3ea8d31b2628a63f84434489fa90e9327..ad57a6a356164f2e3569ac294298551dd0eaf5b7 100644 --- a/incremental/runtime/src/memo/bind.ts +++ b/incremental/runtime/src/memo/bind.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -64,7 +64,7 @@ export function memoBind( { return ( /** @memo */ - () => item(value) + () => { item(value) } ) } @@ -78,7 +78,7 @@ export function memoBind2( { return ( /** @memo */ - () => item(value1, value2) + () => { item(value1, value2) } ) } @@ -93,7 +93,7 @@ export function memoPartialBind2_1( { return ( /** @memo */ - (arg2: T2) => item(value1, arg2) + (arg2: T2) => { item(value1, arg2) } ) } @@ -108,6 +108,6 @@ export function memoPartialBind3_2( { return ( /** @memo */ - (arg2: T2, arg3: T3) => item(value1, arg2, arg3) + (arg2: T2, arg3: T3) => { item(value1, arg2, arg3) } ) } diff --git a/incremental/runtime/test-arkts/memo/bind.test.ts b/incremental/runtime/test-arkts/memo/bind.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..0f3c4981eb69aee4d475d762ef317eb1433e7f51 --- /dev/null +++ b/incremental/runtime/test-arkts/memo/bind.test.ts @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TODO: the real chai exports 'assert', but 'assert' is still a keyword in ArkTS +import { Assert, suite, test } from "../harness" +import { asArray } from "@koalaui/common" +import { + GlobalStateManager, + State, + TestNode, + memoBind, + testTick, +} from "../../src" + +const collector = new Array() + +function testExpected(root: State, ...expected: string[]) { + collector.length = 0 + testTick(root) + Assert.deepEqual(collector, asArray(expected)) + if (expected.length > 0) testExpected(root) +} + +/** @memo */ +function sample(arg: string): void { + collector.push(arg) +} + +suite("memo tests", () => { + test("memoBind trivial test", () => { + GlobalStateManager.reset() + const root = TestNode.create((_) => { + /** @memo */ + const bind = memoBind(sample, "red") + bind() + }) + testExpected(root, "red") + }) +}) diff --git a/incremental/runtime/test/memo/bind.test.ts b/incremental/runtime/test/memo/bind.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..0fe1ab75a54a15265479aa8021f9815360afe8e8 --- /dev/null +++ b/incremental/runtime/test/memo/bind.test.ts @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { assert } from "chai" +import { + GlobalStateManager, + State, + TestNode, + memoBind, + testTick, +} from "../../src" + +const collector = new Array() + +function testExpected(root: State, ...expected: string[]) { + collector.length = 0 + testTick(root) + assert.deepEqual(collector, expected) + if (expected.length > 0) testExpected(root) +} + +/** @memo */ +function sample(arg: string): void { + collector.push(arg) +} + +suite("memo tests", () => { + test("memoBind trivial test", () => { + GlobalStateManager.reset() + const root = TestNode.create(() => { + /** @memo */ + const bind = memoBind(sample, "red") + bind() + }) + testExpected(root, "red") + }) +})