idlize

Форк
0
113 строк · 2.9 Кб
1
/*
2
 * Copyright (c) 2022-2023 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 { KoalaCallsiteKey } from "@koalaui/common"
17
import { __context, __id } from "../internals"
18
import { StateContext } from "../states/State"
19
import { memoEntry1 } from "./entry"
20

21
/** @internal */
22
export class MemoCallbackContext {
23
    private readonly context: StateContext
24
    private readonly id: KoalaCallsiteKey
25

26
    private constructor(context: StateContext, id: KoalaCallsiteKey) {
27
        this.context = context
28
        this.id = id
29
    }
30

31
    /**
32
     * This method stores a memo context to call a memo-function later from non-memo-context.
33
     * Do not use this dangerous API if you do not understand the incremental engine deeply.
34
     * @see call
35
     * @internal
36
     * @memo
37
     */
38
    static Make(): MemoCallbackContext {
39
        return new MemoCallbackContext(__context(), __id())
40
    }
41

42
    /**
43
     * This method allows you to call a memo-function from non-memo-context.
44
     * It can be used only if the state manager is not available, for example, from native code.
45
     * Do not use this dangerous API if you do not understand the incremental engine deeply.
46
     * @internal
47
     */
48
    call(
49
        /** @memo */
50
        callback: (args: Int32Array) => number,
51
        args: Int32Array
52
    ): number {
53
        return memoEntry1(this.context, this.id, callback, args)
54
    }
55
}
56

57
/** @internal */
58
export function memoBind<T>(
59
    /** @memo */
60
    item: (arg: T) => void, value: T
61
):
62
    /** @memo */
63
    () => void
64
{
65
    return (
66
        /** @memo */
67
        () => item(value)
68
    )
69
}
70

71
/** @internal */
72
export function memoBind2<T1, T2>(
73
    /** @memo */
74
    item: (arg1: T1, arg2: T2) => void, value1: T1, value2: T2
75
):
76
    /** @memo */
77
    () => void
78
{
79
    return (
80
        /** @memo */
81
        () => item(value1, value2)
82
    )
83
}
84

85
/** @internal */
86
export function memoPartialBind2_1<T1, T2>(
87
    /** @memo */
88
    item: (arg1: T1, arg2: T2) => void,
89
    value1: T1
90
):
91
    /** @memo */
92
    (arg2: T2) => void
93
{
94
    return (
95
        /** @memo */
96
        (arg2: T2) => item(value1, arg2)
97
    )
98
}
99

100
/** @internal */
101
export function memoPartialBind3_2<T1, T2, T3>(
102
    /** @memo */
103
    item: (arg1: T1, arg2: T2, arg3: T3) => void,
104
    value1: T1
105
):
106
    /** @memo */
107
    (arg2: T2, arg3: T3) => void
108
{
109
    return (
110
        /** @memo */
111
    (arg2: T2, arg3: T3) => item(value1, arg2, arg3)
112
    )
113
}
114

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

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

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

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