diff --git a/arkoala-arkts/libarkts/native/src/generated/bridges.cc b/arkoala-arkts/libarkts/native/src/generated/bridges.cc index 8aaff46e26202837e704f2193827e7dbc08d10ed..dc18f5c0f0a6bb48409db64ed29338af3ccb0397 100644 --- a/arkoala-arkts/libarkts/native/src/generated/bridges.cc +++ b/arkoala-arkts/libarkts/native/src/generated/bridges.cc @@ -8757,33 +8757,6 @@ void impl_IdentifierSetAnnotationUsage(KNativePointer context, KNativePointer re } KOALA_INTEROP_V2(IdentifierSetAnnotationUsage, KNativePointer, KNativePointer); -KBoolean impl_IdentifierIsImplicitThisConst(KNativePointer context, KNativePointer receiver) -{ - const auto _context = reinterpret_cast(context); - const auto _receiver = reinterpret_cast(receiver); - auto result = GetImpl()->IdentifierIsImplicitThisConst(_context, _receiver); - return result; -} -KOALA_INTEROP_2(IdentifierIsImplicitThisConst, KBoolean, KNativePointer, KNativePointer); - -void impl_IdentifierSetImplicitThis(KNativePointer context, KNativePointer receiver) -{ - const auto _context = reinterpret_cast(context); - const auto _receiver = reinterpret_cast(receiver); - GetImpl()->IdentifierSetImplicitThis(_context, _receiver); - return ; -} -KOALA_INTEROP_V2(IdentifierSetImplicitThis, KNativePointer, KNativePointer); - -void impl_IdentifierRemoveImplicitThis(KNativePointer context, KNativePointer receiver) -{ - const auto _context = reinterpret_cast(context); - const auto _receiver = reinterpret_cast(receiver); - GetImpl()->IdentifierRemoveImplicitThis(_context, _receiver); - return ; -} -KOALA_INTEROP_V2(IdentifierRemoveImplicitThis, KNativePointer, KNativePointer); - KNativePointer impl_IdentifierCloneReference(KNativePointer context, KNativePointer receiver, KNativePointer parent) { const auto _context = reinterpret_cast(context); diff --git a/arkoala-arkts/libarkts/src/generated/Es2pandaNativeModule.ts b/arkoala-arkts/libarkts/src/generated/Es2pandaNativeModule.ts index f41d26e198f90911b73b34a5322ba1d4a982e2fc..1e64f6f801470311c58637bae4c9b97305b46075 100644 --- a/arkoala-arkts/libarkts/src/generated/Es2pandaNativeModule.ts +++ b/arkoala-arkts/libarkts/src/generated/Es2pandaNativeModule.ts @@ -2749,15 +2749,6 @@ export class Es2pandaNativeModule { _IdentifierSetAnnotationUsage(context: KNativePointer, receiver: KNativePointer): void { throw new Error("This methods was not overloaded by native module initialization") } - _IdentifierIsImplicitThisConst(context: KNativePointer, receiver: KNativePointer): KBoolean { - throw new Error("This methods was not overloaded by native module initialization") - } - _IdentifierSetImplicitThis(context: KNativePointer, receiver: KNativePointer): void { - throw new Error("This methods was not overloaded by native module initialization") - } - _IdentifierRemoveImplicitThis(context: KNativePointer, receiver: KNativePointer): void { - throw new Error("This methods was not overloaded by native module initialization") - } _IdentifierCloneReference(context: KNativePointer, receiver: KNativePointer, parent: KNativePointer): KNativePointer { throw new Error("This methods was not overloaded by native module initialization") } diff --git a/arkoala-arkts/libarkts/src/generated/peers/Identifier.ts b/arkoala-arkts/libarkts/src/generated/peers/Identifier.ts index cd71334a081ba556718a3aa20f310b6732843c5a..962505a65d010be05ca96954d2ba7b88f81ec652 100644 --- a/arkoala-arkts/libarkts/src/generated/peers/Identifier.ts +++ b/arkoala-arkts/libarkts/src/generated/peers/Identifier.ts @@ -79,9 +79,6 @@ export class Identifier extends AnnotatedExpression { get isAnnotationUsageConst(): boolean { return global.generatedEs2panda._IdentifierIsAnnotationUsageConst(global.context, this.peer) } - get isImplicitThisConst(): boolean { - return global.generatedEs2panda._IdentifierIsImplicitThisConst(global.context, this.peer) - } get typeAnnotationConst(): TypeNode { return unpackNonNullableNode(global.generatedEs2panda._IdentifierTypeAnnotationConst(global.context, this.peer)) } diff --git a/arkoala-arkts/memo-plugin/demo/arktsconfig.json b/arkoala-arkts/memo-plugin/demo/arktsconfig.json index 24a22d2626eeee91d13fbc5c9459c19fb6820a81..36854c9be02cc2e2d25a4cfbcbb67b0aac34baa6 100644 --- a/arkoala-arkts/memo-plugin/demo/arktsconfig.json +++ b/arkoala-arkts/memo-plugin/demo/arktsconfig.json @@ -4,17 +4,8 @@ "outDir": "build/abc", "baseUrl": ".", "paths": { - "@koalaui/compat": [ - "../../../incremental/compat/src/arkts" - ], - "@koalaui/common": [ - "../../../incremental/common/src" - ], "@koalaui/runtime": [ "../runtime-api" - ], - "@koalaui/interop": [ - "../../../interop/src/arkts" ] }, "plugins": [ diff --git a/arkoala-arkts/memo-plugin/runtime-api/animation/AnimatedState.sts b/arkoala-arkts/memo-plugin/runtime-api/animation/AnimatedState.sts new file mode 100644 index 0000000000000000000000000000000000000000..470d228f345a576414cadc88fe34d9eed5070ce2 --- /dev/null +++ b/arkoala-arkts/memo-plugin/runtime-api/animation/AnimatedState.sts @@ -0,0 +1,37 @@ +/* + * 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 { int64 } from "../common" +import { TimeAnimation } from "./TimeAnimation" +import { MutableState, State } from "../states/State" +export declare interface AnimatedState extends State { + animation: TimeAnimation + readonly running: boolean + paused: boolean +} +export declare function animatedState(animation: TimeAnimation, startNow: boolean = false, timeProvider?: () => int64): AnimatedState +export declare interface MutableAnimatedState extends MutableState { + animation: TimeAnimation + readonly running: boolean +} +export declare function mutableAnimatedState(initial: Value, animationProvider: ImplicitAnimationProvider): MutableAnimatedState +export type ImplicitAnimationProvider = (from: Value, to: Value) => TimeAnimation +export declare interface StateAnimator { + parameter: Parameter + readonly value: Value + onValueChange(action: (newValue: Value) => void): void +} +export declare function stateAnimator(parameter: P, animationProvider: ParametrizedAnimationProvider): StateAnimator +export type ParametrizedAnimationProvider = (parameter: P, value: V | undefined) => TimeAnimation diff --git a/arkoala-arkts/memo-plugin/runtime-api/animation/AnimationRange.sts b/arkoala-arkts/memo-plugin/runtime-api/animation/AnimationRange.sts new file mode 100644 index 0000000000000000000000000000000000000000..236cd721e187ff34fc10d889c67c950d81fce58d --- /dev/null +++ b/arkoala-arkts/memo-plugin/runtime-api/animation/AnimationRange.sts @@ -0,0 +1,19 @@ +/* + * 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 { float64 } from "../common" +export type AnimationRange = (value: float64) => Value +export declare function ArrayAnimationRange(from: ReadonlyArray, to: ReadonlyArray, compute: (array: ReadonlyArray) => Value): AnimationRange +export declare function NumberAnimationRange(from: float64, to: float64): AnimationRange diff --git a/arkoala-arkts/memo-plugin/runtime-api/animation/Easing.sts b/arkoala-arkts/memo-plugin/runtime-api/animation/Easing.sts new file mode 100644 index 0000000000000000000000000000000000000000..bc0a01b25938d66a8c826fd653af9a488fd18ebf --- /dev/null +++ b/arkoala-arkts/memo-plugin/runtime-api/animation/Easing.sts @@ -0,0 +1,45 @@ +/* + * 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 { float64, uint32 } from "../common" +export type EasingCurve = (value: float64) => float64 +export declare class Easing { + static readonly Linear: EasingCurve + static readonly LinearReversed: EasingCurve + static readonly EaseInSine: EasingCurve + static readonly EaseOutSine: EasingCurve + static readonly EaseInOutSine: EasingCurve + static readonly Ease: EasingCurve + static readonly EaseIn: EasingCurve + static readonly EaseOut: EasingCurve + static readonly EaseInOut: EasingCurve + static readonly ViscousFluid: EasingCurve + static readonly Bubble: EasingCurve + static inverted(easing: EasingCurve): EasingCurve + static reversed(easing: EasingCurve): EasingCurve + static restarted(easing: EasingCurve): EasingCurve + static repeated(easing: EasingCurve, count: uint32): EasingCurve + static joined(...easing: EasingCurve[]): EasingCurve + static thereAndBackAgain(easing: EasingCurve): EasingCurve + static cubicBezier(p1x: float64, p1y: float64, p2x: float64, p2y: float64): EasingCurve + static steps(stops: uint32, jump: EasingStepJump = EasingStepJump.None): EasingCurve + static viscousFluid(v0: float64 = 1, f: float64 = 3): EasingCurve +} +export enum EasingStepJump { + Start, + End, + None, + Both, +} diff --git a/arkoala-arkts/memo-plugin/runtime-api/animation/EasingSupport.sts b/arkoala-arkts/memo-plugin/runtime-api/animation/EasingSupport.sts new file mode 100644 index 0000000000000000000000000000000000000000..b67f72891ad2545ec1dac601bd8da7393aa61d31 --- /dev/null +++ b/arkoala-arkts/memo-plugin/runtime-api/animation/EasingSupport.sts @@ -0,0 +1,23 @@ +/* + * 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 { float64, uint32 } from "../common" +export declare class EasingSupport { + private x: Float64Array + private y: Float64Array + private constructor(size: uint32, xSupplier: (value: float64) => float64, ySupplier: (value: float64) => float64) + convert(value: float64): float64 + static newCubicBezier(p1x: float64, p1y: float64, p2x: float64, p2y: float64, size: uint32 = 1024): EasingSupport +} diff --git a/arkoala-arkts/memo-plugin/runtime-api/animation/GlobalTimer.sts b/arkoala-arkts/memo-plugin/runtime-api/animation/GlobalTimer.sts new file mode 100644 index 0000000000000000000000000000000000000000..446dd5c9a7b90d1365d48ecf6fa3795912b13880 --- /dev/null +++ b/arkoala-arkts/memo-plugin/runtime-api/animation/GlobalTimer.sts @@ -0,0 +1,20 @@ +/* + * 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 { int64 } from "../common" +import { GlobalStateManager } from "../states/GlobalStateManager" +import { MutableState, StateContext } from "../states/State" +export declare function getAnimationTimer(context: StateContext = GlobalStateManager.instance): MutableState | undefined +export declare function createAnimationTimer(context: StateContext, initial: int64 = 0): MutableState diff --git a/arkoala-arkts/memo-plugin/runtime-api/animation/TimeAnimation.sts b/arkoala-arkts/memo-plugin/runtime-api/animation/TimeAnimation.sts new file mode 100644 index 0000000000000000000000000000000000000000..f82ee817498950739e290acb44be741a425fb900 --- /dev/null +++ b/arkoala-arkts/memo-plugin/runtime-api/animation/TimeAnimation.sts @@ -0,0 +1,60 @@ +/* + * 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 { float64, int32, int64, uint32 } from "../common" +import { AnimationRange } from "./AnimationRange" +import { EasingCurve } from "./Easing" +export declare const DEFAULT_ANIMATION_DURATION: uint32 +export declare interface TimeAnimation { + readonly running: boolean + getValue(time: int64): Value + onStart(time: int64): void + onPause(time: int64): void +} +export declare interface AnimationSpec { + readonly duration: uint32 + readonly delay: uint32 + readonly easing: EasingCurve + readonly onEdge: OnEdge + readonly onPause: OnPause + readonly iterations: int32 | undefined + readonly onStart: (() => void) | undefined + readonly onEnd: (() => void) | undefined + readonly onReset: (() => void) | undefined +} +export declare class OnEdge { + static Nothing: OnEdge + static Reverse: OnEdge + static Restart: OnEdge + private constructor(name: string) +} +export declare class OnPause { + static Nothing: OnPause + static Reset: OnPause + static Fade: OnPause + private constructor(name: string) +} +export declare function constAnimation(value: Value): TimeAnimation +export declare function timeAnimation(compute: (time: int64) => Value, initialTime: int64 = 0): TimeAnimation +export declare function smoothAnimation(period: uint32, from: float64 = 0.0, to: float64 = 1.0): TimeAnimation +export declare function blinkAnimation(period: uint32, initialValue: boolean = false): TimeAnimation +export declare function countAnimation(period: uint32, initialCount: int64 = 0): TimeAnimation +export declare function periodicAnimation(period: uint32, compute: (count: int64) => Value, initialCount: int64 = 0): TimeAnimation +export declare function periodicAnimationWithDelay(delay: uint32, period: uint32, compute: (count: int64) => Value, initialCount: int64 = 0): TimeAnimation +export declare function frameAnimation(frameTime: ReadonlyArray, compute: (index: int64) => Value): TimeAnimation +export declare function numberAnimation(spec: Partial, to: float64 = 1.0, from: float64 = 0.0): TimeAnimation +export declare function animation(spec: Partial, compute: AnimationRange, initialState: float64 = 0): TimeAnimation +export declare function transition(duration: uint32, easing: EasingCurve, compute: AnimationRange, initialState: int64 = 0): TimeAnimation +export declare function linearTransition(duration: uint32, compute: AnimationRange, initialState: int64 = 0): TimeAnimation \ No newline at end of file diff --git a/arkoala-arkts/memo-plugin/runtime-api/animation/memo.sts b/arkoala-arkts/memo-plugin/runtime-api/animation/memo.sts new file mode 100644 index 0000000000000000000000000000000000000000..1ed38006d8ddd1f5345e51b071ae7b7256116ef2 --- /dev/null +++ b/arkoala-arkts/memo-plugin/runtime-api/animation/memo.sts @@ -0,0 +1,28 @@ +/* + * 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 { memo } from "../annotations" +import { float64, int64, uint32 } from "../common" +import { AnimatedState, ImplicitAnimationProvider, MutableAnimatedState, ParametrizedAnimationProvider, StateAnimator, animatedState, mutableAnimatedState, stateAnimator } from "./AnimatedState" +import { AnimationRange } from "./AnimationRange" +import { Easing, EasingCurve } from "./Easing" +import { AnimationSpec, TimeAnimation } from "./TimeAnimation" +@memo export declare function sampledValue(sampleRate: uint32, generator: (tick: int64) => V): V +@memo export declare function rememberAnimatedState(animation: () => TimeAnimation, startNow: boolean = false): AnimatedState +@memo export declare function rememberNumberTransition(on: boolean, duration: uint32, easing: EasingCurve = Easing.Linear, to: float64 = 1.0, from: float64 = 0.0): AnimatedState +@memo export declare function rememberTransition(on: boolean, duration: uint32, easing: EasingCurve, compute: AnimationRange, initial: boolean = on): AnimatedState +@memo export declare function rememberMutableAnimatedState(initial: Value, animationProvider: ImplicitAnimationProvider): MutableAnimatedState +@memo export declare function rememberMutableAnimatedStateNumber(initial: float64, animationSpec: Partial): MutableAnimatedState +@memo export declare function rememberAnimator(parameter: P, animationProvider: ParametrizedAnimationProvider): StateAnimator \ No newline at end of file diff --git a/arkoala-arkts/memo-plugin/runtime-api/annotations.sts b/arkoala-arkts/memo-plugin/runtime-api/annotations.sts new file mode 100644 index 0000000000000000000000000000000000000000..a2e946f10238f3e5f356adff374fd3aaa9518fc3 --- /dev/null +++ b/arkoala-arkts/memo-plugin/runtime-api/annotations.sts @@ -0,0 +1,5 @@ +export @interface memo {} +export @interface memo_intrinsic {} +export @interface memo_entry {} +export @interface memo_stable {} +export @interface memo_skip {} diff --git a/arkoala-arkts/memo-plugin/runtime-api/common.sts b/arkoala-arkts/memo-plugin/runtime-api/common.sts index f8a1d055d837444674815032bf99e4d4e0e455bd..5110a388237c5d43a739573aaeed4ec2a7f3a73f 100644 --- a/arkoala-arkts/memo-plugin/runtime-api/common.sts +++ b/arkoala-arkts/memo-plugin/runtime-api/common.sts @@ -1 +1,5 @@ export type KoalaCallsiteKey = int +export type int32 = int +export type uint32 = int +export type int64 = long +export type float64 = double diff --git a/arkoala-arkts/memo-plugin/runtime-api/index.sts b/arkoala-arkts/memo-plugin/runtime-api/index.sts index 90d3cc3aacccbcdd51797cc51d47a28a1b1385df..a057aae34879253ac1a618cf77faf5de60339c99 100644 --- a/arkoala-arkts/memo-plugin/runtime-api/index.sts +++ b/arkoala-arkts/memo-plugin/runtime-api/index.sts @@ -1,10 +1,165 @@ -import { KoalaCallsiteKey } from "./common" -import { StateContext } from "./states/State" +/* + * 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. + */ -export { memoEntry } from "./memo/entry" -export { GlobalStateManager } from "./states/GlobalStateManager" -export { StateManager, State, Disposable, ComputableState, StateContext } from "./states/State" +export { + AnimatedState, + ImplicitAnimationProvider, + MutableAnimatedState, + ParametrizedAnimationProvider, + StateAnimator, + animatedState, + mutableAnimatedState, + stateAnimator, +} from "./animation/AnimatedState" +export { + AnimationRange, + ArrayAnimationRange, + NumberAnimationRange, +} from "./animation/AnimationRange" +export { + Easing, + EasingCurve, + EasingStepJump, +} from "./animation/Easing" +export { + createAnimationTimer, + getAnimationTimer, +} from "./animation/GlobalTimer" +export { + rememberAnimatedState, + rememberAnimator, + rememberMutableAnimatedState, + rememberMutableAnimatedStateNumber, + rememberNumberTransition, + rememberTransition, + sampledValue, +} from "./animation/memo" +export { + AnimationSpec, + OnEdge, + OnPause, + TimeAnimation, + animation, + blinkAnimation, + constAnimation, + countAnimation, + frameAnimation, + linearTransition, + numberAnimation, + periodicAnimation, + periodicAnimationWithDelay, + smoothAnimation, + timeAnimation, + transition, +} from "./animation/TimeAnimation" -export @interface memo {} -export type __memo_context_type = StateContext -export type __memo_id_type = KoalaCallsiteKey +export { + memoBind, + memoBind2, + memoPartialBind2_1, + memoPartialBind3_2, + MemoCallbackContext, +} from "./memo/bind" +export { + OnChange, + RunEffect, +} from "./memo/changeListener" +export { + contextLocal, + contextLocalScope, + contextLocalValue, +} from "./memo/contextLocal" +export { + memoRoot, + memoEntry, + memoEntry1, + memoEntry2, +} from "./memo/entry" +export { + DataNode, + NodeAttach, + contextNode, +} from "./memo/node" +export { + memoize, + memoLifecycle, + once, + remember, + rememberArrayState, + rememberComputableState, + rememberComputableValue, + rememberControlledScope, + rememberDisposable, + rememberMutableAsyncState, + rememberMutableState, +} from "./memo/remember" +export { + Repeat, + RepeatByArray, + RepeatRange, + RepeatWithKey, +} from "./memo/repeat" +export { + TestNode, + testRoot, + testTick, + testUpdate, +} from "./memo/testing" + +export { + Disposable, + disposeContent, + disposeContentBackward, + disposeContentForward, +} from "./states/Disposable" +export { + GlobalStateManager, + arrayState, + callScheduledCallbacks, + mutableState, + scheduleCallback, + updateStateManager, +} from "./states/GlobalStateManager" +export { + ArrayState, + CONTEXT_ROOT_NODE, + CONTEXT_ROOT_SCOPE, + ComputableState, + ControlledScope, + Equivalent, + MutableState, + State, + StateContext, + StateManager, + ValueTracker, +} from "./states/State" +export { + __context, + __id, + __key, + __memo_context_type, + __memo_id_type, + __memo_transformed, + __memo_transformed_before, + __memo_transformed_after, +} from "./internals" + +export { IncrementalNode } from "./tree/IncrementalNode" +export { PrimeNumbers } from "./tree/PrimeNumbers" +export { ReadonlyTreeNode } from "./tree/ReadonlyTreeNode" +export { TreeNode } from "./tree/TreeNode" +export { TreePath } from "./tree/TreePath" + +export { memo, memo_intrinsic, memo_entry, memo_stable, memo_skip } from "./annotations" diff --git a/arkoala-arkts/memo-plugin/runtime-api/internals.sts b/arkoala-arkts/memo-plugin/runtime-api/internals.sts new file mode 100644 index 0000000000000000000000000000000000000000..b8f3ff6a2f551b9e2bd973353b3b586511c28192 --- /dev/null +++ b/arkoala-arkts/memo-plugin/runtime-api/internals.sts @@ -0,0 +1,25 @@ +/* + * 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 { KoalaCallsiteKey } from "./common" +import { StateContext } from "./states/State" +export type __memo_context_type = StateContext +export type __memo_id_type = KoalaCallsiteKey +export type __memo_transformed_before = string +export type __memo_transformed_after = number +export type __memo_transformed = __memo_transformed_before +export declare function __context(): StateContext +export declare function __id(): KoalaCallsiteKey +export declare function __key(): KoalaCallsiteKey diff --git a/arkoala-arkts/memo-plugin/runtime-api/memo/bind.sts b/arkoala-arkts/memo-plugin/runtime-api/memo/bind.sts new file mode 100644 index 0000000000000000000000000000000000000000..05d1bed2a3d3ac7844ec539c35bb8b871527a941 --- /dev/null +++ b/arkoala-arkts/memo-plugin/runtime-api/memo/bind.sts @@ -0,0 +1,29 @@ +/* + * 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 { memo } from "../annotations" +import { KoalaCallsiteKey } from "../common" +import { StateContext } from "../states/State" +export declare class MemoCallbackContext { + private readonly context: StateContext + private readonly id: KoalaCallsiteKey + private constructor(context: StateContext, id: KoalaCallsiteKey) + @memo static Make(): MemoCallbackContext + call(@memo callback: (args: Int32Array) => number, args: Int32Array): number +} +export declare function memoBind(@memo item: (arg: T) => void, value: T): @memo () => void +export declare function memoBind2(@memo item: (arg1: T1, arg2: T2) => void, value1: T1, value2: T2): @memo () => void +export declare function memoPartialBind2_1(@memo item: (arg1: T1, arg2: T2) => void, value1: T1): @memo (arg2: T2) => void +export declare function memoPartialBind3_2(@memo item: (arg1: T1, arg2: T2, arg3: T3) => void, value1: T1): @memo (arg2: T2, arg3: T3) => void diff --git a/arkoala-arkts/memo-plugin/runtime-api/memo/changeListener.sts b/arkoala-arkts/memo-plugin/runtime-api/memo/changeListener.sts new file mode 100644 index 0000000000000000000000000000000000000000..bcaa2a50c47b344a787a2c5d694dcc818ab14a3c --- /dev/null +++ b/arkoala-arkts/memo-plugin/runtime-api/memo/changeListener.sts @@ -0,0 +1,18 @@ +/* + * 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 { memo_intrinsic } from "../annotations" +@memo_intrinsic export declare function OnChange(value: Value, listener: (value: Value) => void): void +@memo_intrinsic export declare function RunEffect(value: Value, effect: (value: Value) => void): void diff --git a/arkoala-arkts/memo-plugin/runtime-api/memo/contextLocal.sts b/arkoala-arkts/memo-plugin/runtime-api/memo/contextLocal.sts new file mode 100644 index 0000000000000000000000000000000000000000..5cfb10ee7d897ea385e7948b24889d8a6482d536 --- /dev/null +++ b/arkoala-arkts/memo-plugin/runtime-api/memo/contextLocal.sts @@ -0,0 +1,20 @@ +/* + * 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 { memo, memo_intrinsic } from "../annotations" +import { State } from "../states/State" +@memo_intrinsic export declare function contextLocal(name: string): State | undefined +@memo_intrinsic export declare function contextLocalValue(name: string): Value +@memo_intrinsic export declare function contextLocalScope(name: string, value: Value, @memo content: () => void): void diff --git a/arkoala-arkts/memo-plugin/runtime-api/memo/entry.sts b/arkoala-arkts/memo-plugin/runtime-api/memo/entry.sts index 0c75014655b81ac76167ad32470d82cf11872a72..2b7d437692caabd2befdeee696267a31a0b580b1 100644 --- a/arkoala-arkts/memo-plugin/runtime-api/memo/entry.sts +++ b/arkoala-arkts/memo-plugin/runtime-api/memo/entry.sts @@ -1,4 +1,27 @@ -import { KoalaCallsiteKey } from "../common" -import { StateContext } from "../states/State" +/* + * 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. + */ -export declare function memoEntry(__memo_context: StateContext, __memo_id: KoalaCallsiteKey, entry: (__memo_context: StateContext, __memo_id: KoalaCallsiteKey) => R): R +import { memo, memo_entry } from "../annotations" +import { KoalaCallsiteKey } from "../common" +import { ComputableState, StateContext } from "../states/State" +import { IncrementalNode } from "../tree/IncrementalNode" +export declare function memoRoot(node: Node, @memo update: (node: Node) => void): ComputableState +export declare function memoRoot(node: Node, update: (__memo_context: StateContext, __memo_id: KoalaCallsiteKey, node: Node) => void): ComputableState +@memo_entry export declare function memoEntry(__memo_context: StateContext, __memo_id: KoalaCallsiteKey, @memo entry: () => R): R +@memo_entry export declare function memoEntry(__memo_context: StateContext, __memo_id: KoalaCallsiteKey, entry: (__memo_context: StateContext, __memo_id: KoalaCallsiteKey) => R): R +@memo_entry export declare function memoEntry1(__memo_context: StateContext, __memo_id: KoalaCallsiteKey, @memo entry: (arg: T) => R, arg: T): R +@memo_entry export declare function memoEntry1(__memo_context: StateContext, __memo_id: KoalaCallsiteKey, entry: (__memo_context: StateContext, __memo_id: KoalaCallsiteKey, arg: T) => R, arg: T): R +@memo_entry export declare function memoEntry2(__memo_context: StateContext, __memo_id: KoalaCallsiteKey, @memo entry: (arg1: T1, arg2: T2) => R, arg1: T1, arg2: T2): R +@memo_entry export declare function memoEntry2(__memo_context: StateContext, __memo_id: KoalaCallsiteKey, entry: (__memo_context: StateContext, __memo_id: KoalaCallsiteKey, arg1: T1, arg2: T2) => R, arg1: T1, arg2: T2): R diff --git a/arkoala-arkts/memo-plugin/runtime-api/memo/node.sts b/arkoala-arkts/memo-plugin/runtime-api/memo/node.sts new file mode 100644 index 0000000000000000000000000000000000000000..45d2bc127098e8c1d9b5d3a7d2d859d74c718e05 --- /dev/null +++ b/arkoala-arkts/memo-plugin/runtime-api/memo/node.sts @@ -0,0 +1,29 @@ +/* + * 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 { memo, memo_intrinsic } from "../annotations" +import { uint32, KoalaCallsiteKey } from "../common" +import { IncrementalNode } from "../tree/IncrementalNode" +import { StateContext } from "../states/State" +@memo_intrinsic export declare function NodeAttach(create: () => Node, @memo update: (node: Node) => void): void +@memo_intrinsic export declare function contextNode(kind: uint32 = 1, name?: string): T +export declare function NodeAttach(__memo_context: StateContext, __memo_id: KoalaCallsiteKey, create: () => Node, update: (__memo_context: StateContext, __memo_id: KoalaCallsiteKey, node: Node) => void): void +export declare function contextNode(__memo_context: StateContext, __memo_id: KoalaCallsiteKey, kind: uint32 = 1, name?: string): T +export declare class DataNode extends IncrementalNode { + private data: Data | undefined + constructor(kind: uint32 = 1) + static attach(kind: uint32, data: Data, onDataChange?: () => void): void + static extract(kind: uint32, node: IncrementalNode): Data | undefined +} diff --git a/arkoala-arkts/memo-plugin/runtime-api/memo/remember.sts b/arkoala-arkts/memo-plugin/runtime-api/memo/remember.sts new file mode 100644 index 0000000000000000000000000000000000000000..3476df08bbba4fd0579b0da1675421894d97720d --- /dev/null +++ b/arkoala-arkts/memo-plugin/runtime-api/memo/remember.sts @@ -0,0 +1,28 @@ +/* + * 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 { memo, memo_skip, memo_intrinsic } from "../annotations" +import { ArrayState, ControlledScope, MutableState } from "../states/State" +@memo_intrinsic export declare function memoize(compute: () => Value): Value +@memo_intrinsic export declare function memoLifecycle(onAttach: () => void, onDetach: () => void): void +@memo_intrinsic export declare function once(callback: () => void): void +@memo_intrinsic export declare function remember(compute: () => Value): Value +@memo_intrinsic export declare function rememberDisposable(compute: () => Value, cleanup: (value: Value | undefined) => void): Value +@memo_intrinsic export declare function rememberMutableState(initial: (() => Value) | Value): MutableState +@memo_intrinsic export declare function rememberArrayState(initial?: () => ReadonlyArray): ArrayState +@memo export declare function rememberMutableAsyncState(compute: () => Promise, initial?: Value, onError?: (error: Error) => void): MutableState +@memo export declare function rememberComputableState(key: Key, @memo_skip compute: (key: Key) => Promise, initial?: Value, onError?: (error: Error) => void): MutableState +@memo export declare function rememberComputableValue(key: Key, @memo_skip compute: (key: Key) => Promise, initial?: Value, onError?: (e: Error) => void): Value | undefined +@memo_intrinsic export declare function rememberControlledScope(invalidate: () => void): ControlledScope diff --git a/arkoala-arkts/memo-plugin/runtime-api/memo/repeat.sts b/arkoala-arkts/memo-plugin/runtime-api/memo/repeat.sts new file mode 100644 index 0000000000000000000000000000000000000000..d12ad9abf369e186f0a5c7e5ee4d0ce112823a0d --- /dev/null +++ b/arkoala-arkts/memo-plugin/runtime-api/memo/repeat.sts @@ -0,0 +1,26 @@ +/* + * 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 { memo } from "../annotations" +import { KoalaCallsiteKey, int32 } from "../common" +import { StateContext } from "../states/State" +@memo export declare function Repeat(count: int32, @memo action: (index: int32) => void): void +export declare function Repeat(__memo_context: StateContext, __memo_id: KoalaCallsiteKey, count: int32, action: (__memo_context: StateContext, __memo_id: KoalaCallsiteKey, index: int32) => void): void +@memo export declare function RepeatWithKey(count: int32, key: (index: int32) => KoalaCallsiteKey, @memo action: (index: int32) => void): void +export declare function RepeatWithKey(__memo_context: StateContext, __memo_id: KoalaCallsiteKey, count: int32, key: (index: int32) => KoalaCallsiteKey, action: (__memo_context: StateContext, __memo_id: KoalaCallsiteKey, index: int32) => void): void +@memo export declare function RepeatByArray(array: ReadonlyArray, key: (element: T, index: int32) => KoalaCallsiteKey, @memo action: (element: T, index: int32) => void): void +export declare function RepeatByArray(__memo_context: StateContext, __memo_id: KoalaCallsiteKey, array: ReadonlyArray, key: (element: T, index: int32) => KoalaCallsiteKey, action: (__memo_context: StateContext, __memo_id: KoalaCallsiteKey, element: T, index: int32) => void): void +@memo export declare function RepeatRange(start: int32, end: int32, element: (index: int32) => T, key: (element: T, index: int32) => KoalaCallsiteKey, @memo action: (element: T, index: int32) => void): void +export declare function RepeatRange(__memo_context: StateContext, __memo_id: KoalaCallsiteKey, start: int32, end: int32, element: (index: int32) => T, key: (element: T, index: int32) => KoalaCallsiteKey, action: (__memo_context: StateContext, __memo_id: KoalaCallsiteKey, element: T, index: int32) => void): void diff --git a/arkoala-arkts/memo-plugin/runtime-api/memo/testing.sts b/arkoala-arkts/memo-plugin/runtime-api/memo/testing.sts new file mode 100644 index 0000000000000000000000000000000000000000..57d9b70b6f17a99d2cc1f1ee50e19385dc1e4858 --- /dev/null +++ b/arkoala-arkts/memo-plugin/runtime-api/memo/testing.sts @@ -0,0 +1,33 @@ +/* + * 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 { memo, memo_intrinsic } from "../annotations" +import { uint32, KoalaCallsiteKey } from "../common" +import { GlobalStateManager } from "../states/GlobalStateManager" +import { ComputableState, State, StateContext, StateManager } from "../states/State" +import { IncrementalNode } from "../tree/IncrementalNode" +export declare class TestNode extends IncrementalNode { + content: string + constructor(kind: uint32 = 1) + toString(): string + static create(@memo content: (node: TestNode) => void): ComputableState + static create(content: (__memo_context: StateContext, __memo_id: KoalaCallsiteKey, node: TestNode) => void): ComputableState + @memo_intrinsic static attach(content: (node: TestNode) => void): void + @memo_intrinsic static attach(content: (__memo_context: StateContext, __memo_id: KoalaCallsiteKey, node: TestNode) => void): void +} +export declare function testRoot(@memo content: (node: TestNode) => void): State +export declare function testRoot(content: (__memo_context: StateContext, __memo_id: KoalaCallsiteKey, node: TestNode) => void): State +export declare function testUpdate(withCallbacks: boolean = true, manager: StateManager = GlobalStateManager.instance): uint32 +export declare function testTick(root: State, withCallbacks: boolean = true): void diff --git a/arkoala-arkts/memo-plugin/runtime-api/states/Dependency.sts b/arkoala-arkts/memo-plugin/runtime-api/states/Dependency.sts new file mode 100644 index 0000000000000000000000000000000000000000..88b8b10f962f8727b8513dd4c56e0a90486a190d --- /dev/null +++ b/arkoala-arkts/memo-plugin/runtime-api/states/Dependency.sts @@ -0,0 +1,27 @@ +/* + * 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. + */ + +export declare interface Dependency { + readonly obsolete: boolean + invalidate(): void +} +export declare class Dependencies { + private frame: int + private dependencies: Set | undefined + private latest: Dependency | undefined + get empty(): boolean + register(dependency?: Dependency): void + updateDependencies(invalidate: boolean): void +} diff --git a/arkoala-arkts/memo-plugin/runtime-api/states/Disposable.sts b/arkoala-arkts/memo-plugin/runtime-api/states/Disposable.sts new file mode 100644 index 0000000000000000000000000000000000000000..59d045a473691c62aeadea59676ecf8e40d6f8dd --- /dev/null +++ b/arkoala-arkts/memo-plugin/runtime-api/states/Disposable.sts @@ -0,0 +1,22 @@ +/* + * 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. + */ + +export declare interface Disposable { + readonly disposed: boolean + dispose(): void +} +export declare function disposeContentForward(array: ReadonlyArray): void +export declare function disposeContentBackward(array: ReadonlyArray): void +export declare function disposeContent(it: IterableIterator): void diff --git a/arkoala-arkts/memo-plugin/runtime-api/states/GlobalStateManager.sts b/arkoala-arkts/memo-plugin/runtime-api/states/GlobalStateManager.sts index bc62a899279be20d05d918901244acf4c927f47b..2fe51fcab0dca2ac07711da156afc2a7559724fc 100644 --- a/arkoala-arkts/memo-plugin/runtime-api/states/GlobalStateManager.sts +++ b/arkoala-arkts/memo-plugin/runtime-api/states/GlobalStateManager.sts @@ -1,5 +1,26 @@ -import { StateManager } from "./State" +/* + * 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 { ArrayState, Equivalent, MutableState, StateManager, ValueTracker } from "./State" export declare class GlobalStateManager { + private static current: StateManager | undefined static get instance(): StateManager + static reset(): void } +export declare function updateStateManager(manager: StateManager = GlobalStateManager.instance): void +export declare function callScheduledCallbacks(manager: StateManager = GlobalStateManager.instance): void +export declare function scheduleCallback(callback?: () => void, manager: StateManager = GlobalStateManager.instance): void +export declare function mutableState(value: T, equivalent?: Equivalent, tracker?: ValueTracker): MutableState +export declare function arrayState(array?: ReadonlyArray, equivalent?: Equivalent): ArrayState diff --git a/arkoala-arkts/memo-plugin/runtime-api/states/Journal.sts b/arkoala-arkts/memo-plugin/runtime-api/states/Journal.sts new file mode 100644 index 0000000000000000000000000000000000000000..cab0f9d85351c24ae48e729ef0a798e4144157b6 --- /dev/null +++ b/arkoala-arkts/memo-plugin/runtime-api/states/Journal.sts @@ -0,0 +1,34 @@ +/* + * 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 { AtomicRef } from "../common" +export interface Changes { + getChange(state: Object): AtomicRef | undefined + clear(): void +} +export declare class Journal implements Changes { + private readonly current: AtomicRef + setMarker(): void + addChange(state: Object, value: Value): void + getChanges(): Changes | undefined + getChange(state: Object): AtomicRef | undefined + clear(): void + getCachedArray(state: Object, array: Array): Array +} +declare class Chunk { + readonly previous: AtomicRef + readonly map: Map + get(state: Object): AtomicRef | undefined +} diff --git a/arkoala-arkts/memo-plugin/runtime-api/states/State.sts b/arkoala-arkts/memo-plugin/runtime-api/states/State.sts index afd523fe6e250ef3e53240380e8ba5588d54dda4..0277e11149a378b715392c12e4360c15c8702d0e 100644 --- a/arkoala-arkts/memo-plugin/runtime-api/states/State.sts +++ b/arkoala-arkts/memo-plugin/runtime-api/states/State.sts @@ -1,19 +1,84 @@ -export declare interface StateManager extends StateContext { } +/* + * 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 { int32, KoalaCallsiteKey, uint32 } from "../common" +import { Disposable } from "./Disposable" +import { IncrementalNode } from "../tree/IncrementalNode" +export declare const CONTEXT_ROOT_SCOPE: string +export declare const CONTEXT_ROOT_NODE: string +export type Equivalent = (oldV: Value, newV: Value) => boolean +export declare function createStateManager(): StateManager +export declare interface StateManager extends StateContext { + syncChanges(): void + isUpdateNeeded(): boolean + updateSnapshot(): uint32 + updatableNode(node: Node, update: (context: StateContext) => void, cleanup?: () => void): ComputableState + scheduleCallback(callback: () => void): void + callCallbacks(): void + frozen: boolean + reset(): void +} export declare interface State { - modified: boolean + readonly modified: boolean + readonly value: Value +} +export declare interface MutableState extends Disposable, State { value: Value } -export interface Disposable { - disposed: boolean - dispose(): void +export declare interface ArrayState extends State> { + length: number + at(index: number): Item + get(index: number): Item + set(index: number, item: Item): void + copyWithin(target: number, start: number, end?: number): Array + fill(value: Item, start?: number, end?: number): Array + pop(): Item | undefined + push(...items: Item[]): number + reverse(): Array + shift(): Item | undefined + sort(comparator?: (a: Item, b: Item) => number): Array + splice(start: number, deleteCount: number | undefined, ...items: Item[]): Array + unshift(...items: Item[]): number +} +export declare interface ComputableState extends Disposable, State { + readonly recomputeNeeded: boolean } -export interface InternalScope { +export declare interface StateContext { + readonly node: IncrementalNode | undefined + attach(id: KoalaCallsiteKey, create: () => Node, update: () => void, cleanup?: () => void): void + compute(id: KoalaCallsiteKey, compute: () => Value, cleanup?: (value: Value | undefined) => void, once?: boolean): Value + computableState(compute: (context: StateContext) => Value, cleanup?: (context: StateContext, value: Value | undefined) => void): ComputableState + mutableState(initial: Value, global?: boolean, equivalent?: Equivalent, tracker?: ValueTracker): MutableState + arrayState(initial?: ReadonlyArray, global?: boolean, equivalent?: Equivalent): ArrayState + namedState(name: string, create: () => Value, global?: boolean, equivalent?: Equivalent, tracker?: ValueTracker): MutableState + stateBy(name: string, global?: boolean): MutableState | undefined + valueBy(name: string, global?: boolean): Value + scope(id: KoalaCallsiteKey, paramCount?: int32, create?: () => IncrementalNode, compute?: () => Value, cleanup?: (value: Value | undefined) => void, once?: boolean): InternalScope + controlledScope(id: KoalaCallsiteKey, invalidate: () => void): ControlledScope +} +export declare interface ValueTracker { + onCreate(value: Value): Value + onUpdate(value: Value): Value +} +export declare interface InternalScope { readonly unchanged: boolean readonly cached: Value recache(newValue?: Value): Value + param(index: int32, value: V, equivalent?: Equivalent, name?: string, contextLocal?: boolean): State } -export declare interface ComputableState extends Disposable, State { } -export declare interface StateContext { - computableState(compute: (context: StateContext) => Value, cleanup?: (context: StateContext, value: Value | undefined) => void): ComputableState - scope(id: int): InternalScope +export declare interface ControlledScope { + enter(): void + leave(): void } diff --git a/arkoala-arkts/memo-plugin/runtime-api/tree/IncrementalNode.sts b/arkoala-arkts/memo-plugin/runtime-api/tree/IncrementalNode.sts new file mode 100644 index 0000000000000000000000000000000000000000..19d81f21394cca91332033ff28a4ad9e53ba3bbb --- /dev/null +++ b/arkoala-arkts/memo-plugin/runtime-api/tree/IncrementalNode.sts @@ -0,0 +1,41 @@ +/* + * 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 { uint32 } from "../common" +import { Disposable } from "../states/Disposable" +import { ReadonlyTreeNode } from "./ReadonlyTreeNode" +export declare class IncrementalNode implements Disposable, ReadonlyTreeNode { + private _disposed: boolean + private _child: IncrementalNode | undefined + private _prev: IncrementalNode | undefined + private _next: IncrementalNode | undefined + private _parent: IncrementalNode | undefined + private _incremental: IncrementalNode | undefined + protected onChildInserted: ((node: IncrementalNode) => void) | undefined + protected onChildRemoved: ((node: IncrementalNode) => void) | undefined + readonly kind: uint32 + constructor(kind: uint32 = 1) + isKind(kind: uint32): boolean + get disposed(): boolean + dispose(): void + get parent(): IncrementalNode | undefined + toString(): string + toHierarchy(): string + get firstChild(): IncrementalNode | undefined + get nextSibling(): IncrementalNode | undefined + get previousSibling(): IncrementalNode | undefined + incrementalUpdateSkip(count: uint32): void + incrementalUpdateDone(parent?: IncrementalNode): void +} diff --git a/arkoala-arkts/memo-plugin/runtime-api/tree/PrimeNumbers.sts b/arkoala-arkts/memo-plugin/runtime-api/tree/PrimeNumbers.sts new file mode 100644 index 0000000000000000000000000000000000000000..d5994c577d651db34a50fa114dd3fcb01eee0e6a --- /dev/null +++ b/arkoala-arkts/memo-plugin/runtime-api/tree/PrimeNumbers.sts @@ -0,0 +1,17 @@ +/* + * 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 { uint32 } from "../common" +export declare const PrimeNumbers: ReadonlyArray \ No newline at end of file diff --git a/arkoala-arkts/memo-plugin/runtime-api/tree/ReadonlyTreeNode.sts b/arkoala-arkts/memo-plugin/runtime-api/tree/ReadonlyTreeNode.sts new file mode 100644 index 0000000000000000000000000000000000000000..7c7d9f52f3be133480b08e379ad67ae35c9ed8d9 --- /dev/null +++ b/arkoala-arkts/memo-plugin/runtime-api/tree/ReadonlyTreeNode.sts @@ -0,0 +1,19 @@ +/* + * 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. + */ + +export declare interface ReadonlyTreeNode { + readonly parent: ReadonlyTreeNode | undefined + toHierarchy(): string +} diff --git a/arkoala-arkts/memo-plugin/runtime-api/tree/TreeNode.sts b/arkoala-arkts/memo-plugin/runtime-api/tree/TreeNode.sts new file mode 100644 index 0000000000000000000000000000000000000000..60cc044103902dc8ab668aa52a26a1e24826f7f9 --- /dev/null +++ b/arkoala-arkts/memo-plugin/runtime-api/tree/TreeNode.sts @@ -0,0 +1,59 @@ +/* + * 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 { float64, int32, uint32 } from "../common" +import { Disposable } from "../states/Disposable" +import { ReadonlyTreeNode } from "./ReadonlyTreeNode" +export declare class TreeNode implements Disposable, ReadonlyTreeNode { + private myIndex: int32 + private myParent: TreeNode | undefined + private myChildren: Array + private myIndicesValid: boolean + private myDisposed: boolean + readonly kind: uint32 + protected onChildInserted: ((node: TreeNode, index: int32) => void) | undefined + protected onChildRemoved: ((node: TreeNode, index: int32) => void) | undefined + constructor(kind: uint32 = 1) + get disposed(): boolean + dispose(): void + get parent(): TreeNode | undefined + get depth(): uint32 + get childrenCount(): uint32 + get children(): ReadonlyArray + get index(): int32 + isKind(kind: uint32): boolean + find(valueOf: (node: TreeNode, index: int32) => V | undefined): V | undefined + forEach(action: (node: TreeNode, index: float64) => void): void + every(predicate: (node: TreeNode, index: float64) => boolean): boolean + some(predicate: (node: TreeNode, index: float64) => boolean): boolean + childAt(index: int32): TreeNode | undefined + appendChild(node: TreeNode): boolean + insertChildAt(index: int32, node: TreeNode): boolean + appendChildren(...nodes: TreeNode[]): boolean + insertChildrenAt(index: int32, ...nodes: TreeNode[]): boolean + removeChildAt(index: int32): TreeNode | undefined + removeChildrenAt(index: int32, count?: uint32): Array + removeChild(node: TreeNode): boolean + removeFromParent(): void + private removeNodes(index: int32, count: uint32): Array + private insertNodeAt(index: int32, node: TreeNode): void + private insertable(node: TreeNode): boolean + private accessible(index: int32, count: uint32 = 1): boolean + toString(): string + toHierarchy(): string + collectNodes(): Array + collectParentsTo(array: Array): void + collectChildrenTo(array: Array, deep: boolean = false): void +} diff --git a/arkoala-arkts/memo-plugin/runtime-api/tree/TreePath.sts b/arkoala-arkts/memo-plugin/runtime-api/tree/TreePath.sts new file mode 100644 index 0000000000000000000000000000000000000000..55be5f191c5d76c670c31a419c46f4a489e36028 --- /dev/null +++ b/arkoala-arkts/memo-plugin/runtime-api/tree/TreePath.sts @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2022-2024 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 { uint32 } from "../common" +export declare class TreePath { + readonly node: Node + readonly parent: TreePath | undefined + constructor(node: Node, parent?: TreePath) + child(node: Node): TreePath + get root(): TreePath + get depth(): uint32 + toString(): string +} diff --git a/arkoala-arkts/memo-plugin/runtime-api/tree/TreeUpdater.sts b/arkoala-arkts/memo-plugin/runtime-api/tree/TreeUpdater.sts new file mode 100644 index 0000000000000000000000000000000000000000..173a8ac4b94dccca5d2c1ec335c8983015b6211e --- /dev/null +++ b/arkoala-arkts/memo-plugin/runtime-api/tree/TreeUpdater.sts @@ -0,0 +1,30 @@ +/* + * 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 { int32, uint32 } from "../common" +import { TreePath } from "./TreePath" +export declare class TreeUpdater { + private current: TreePath + readonly reverse: boolean + constructor(root: Node, reverse: boolean = false) + get path(): TreePath + get node(): Node + down(node: Node): void + up(): void + clear(): void + insert(index: int32, node: Node): void + remove(index: int32, amount: uint32): void + move(indexFrom: int32, indexTo: int32, amount: uint32): void +} diff --git a/arkoala-arkts/memo-plugin/src/utils.ts b/arkoala-arkts/memo-plugin/src/utils.ts index e78b22ef47b3b2286bff559f305290df2d4dc7c0..e3746e9253bb323b196ee4da822b8a723e8bedd3 100644 --- a/arkoala-arkts/memo-plugin/src/utils.ts +++ b/arkoala-arkts/memo-plugin/src/utils.ts @@ -13,7 +13,7 @@ * limitations under the License. */ -import { parseNumber, UniqueId } from "@koalaui/common" +import { UniqueId } from "@koalaui/common" import * as arkts from "@koalaui/libarkts" export enum RuntimeNames {