idlize

Форк
0
66 строк · 1.9 Кб
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

16
import { uint32 } from "@koalaui/common"
17
import { callScheduledCallbacks, updateStateManager } from "../states/GlobalStateManager"
18
import { ComputableState, State } from "../states/State"
19
import { IncrementalNode } from "../tree/IncrementalNode"
20
import { memoRoot } from "./entry"
21
import { NodeAttach } from "./node"
22

23
/** @internal */
24
export class TestNode extends IncrementalNode {
25
    content: string = "<UNDEFINED>"
26

27
    constructor(kind: uint32 = 1) {
28
        super(kind)
29
    }
30

31
    toString(): string {
32
        return this.content
33
    }
34

35
    static create(
36
        /** @memo */
37
        content: (node: TestNode) => void
38
    ): ComputableState<TestNode> {
39
        return memoRoot(new TestNode(), content)
40
    }
41

42
    /** @memo:intrinsic */
43
    static attach(
44
        /** @memo */
45
        content: (node: TestNode) => void
46
    ) {
47
        NodeAttach(() => new TestNode(), content)
48
    }
49
}
50

51
/** @internal */
52
export function testRoot(
53
    /** @memo */
54
    content: (node: TestNode) => void
55
): State<TestNode> {
56
    const root = TestNode.create(content)
57
    root.value
58
    return root
59
}
60

61
/** @internal */
62
export function testTick<Node extends IncrementalNode>(root: State<Node>, withCallbacks: boolean = true) {
63
    updateStateManager()
64
    root.value
65
    if (withCallbacks) callScheduledCallbacks()
66
}
67

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.