idlize
1/*
2* Copyright (c) 2022-2024 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 { uint32 } from "@koalaui/common"17import { callScheduledCallbacks, updateStateManager } from "../states/GlobalStateManager"18import { ComputableState, State } from "../states/State"19import { IncrementalNode } from "../tree/IncrementalNode"20import { memoRoot } from "./entry"21import { NodeAttach } from "./node"22
23/** @internal */
24export class TestNode extends IncrementalNode {25content: string = "<UNDEFINED>"26
27constructor(kind: uint32 = 1) {28super(kind)29}30
31toString(): string {32return this.content33}34
35static create(36/** @memo */37content: (node: TestNode) => void38): ComputableState<TestNode> {39return memoRoot(new TestNode(), content)40}41
42/** @memo:intrinsic */43static attach(44/** @memo */45content: (node: TestNode) => void46) {47NodeAttach(() => new TestNode(), content)48}49}
50
51/** @internal */
52export function testRoot(53/** @memo */54content: (node: TestNode) => void55): State<TestNode> {56const root = TestNode.create(content)57root.value58return root59}
60
61/** @internal */
62export function testTick<Node extends IncrementalNode>(root: State<Node>, withCallbacks: boolean = true) {63updateStateManager()64root.value65if (withCallbacks) callScheduledCallbacks()66}
67