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
7
* http://www.apache.org/licenses/LICENSE-2.0
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.
16
import { KoalaCallsiteKey } from "@koalaui/common"
17
import { __context, __id } from "../internals"
18
import { StateContext } from "../states/State"
19
import { memoEntry1 } from "./entry"
22
export class MemoCallbackContext {
23
private readonly context: StateContext
24
private readonly id: KoalaCallsiteKey
26
private constructor(context: StateContext, id: KoalaCallsiteKey) {
27
this.context = context
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.
38
static Make(): MemoCallbackContext {
39
return new MemoCallbackContext(__context(), __id())
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.
50
callback: (args: Int32Array) => number,
53
return memoEntry1(this.context, this.id, callback, args)
58
export function memoBind<T>(
60
item: (arg: T) => void, value: T
72
export function memoBind2<T1, T2>(
74
item: (arg1: T1, arg2: T2) => void, value1: T1, value2: T2
81
() => item(value1, value2)
86
export function memoPartialBind2_1<T1, T2>(
88
item: (arg1: T1, arg2: T2) => void,
96
(arg2: T2) => item(value1, arg2)
101
export function memoPartialBind3_2<T1, T2, T3>(
103
item: (arg1: T1, arg2: T2, arg3: T3) => void,
107
(arg2: T2, arg3: T3) => void
111
(arg2: T2, arg3: T3) => item(value1, arg2, arg3)