1 | /**
|
2 | * Copyright (c) Meta Platforms, Inc. and affiliates.
|
3 | *
|
4 | * This source code is licensed under the MIT license found in the
|
5 | * LICENSE file in the root directory of this source tree.
|
6 | *
|
7 | * @format
|
8 | */
|
9 |
|
10 | import {EmitterSubscription} from '../vendor/emitter/EventEmitter';
|
11 |
|
12 | export type Handle = number;
|
13 |
|
14 | export type SimpleTask = {
|
15 | name: string;
|
16 | gen: () => void;
|
17 | };
|
18 | export type PromiseTask = {
|
19 | name: string;
|
20 | gen: () => Promise<any>;
|
21 | };
|
22 |
|
23 | export interface InteractionManagerStatic {
|
24 | Events: {
|
25 | interactionStart: string;
|
26 | interactionComplete: string;
|
27 | };
|
28 |
|
29 | /**
|
30 | * Adds a listener to be invoked when events of the specified type are
|
31 | * emitted. An optional calling context may be provided. The data arguments
|
32 | * emitted will be passed to the listener function.
|
33 | *
|
34 | * @param eventType - Name of the event to listen to
|
35 | * @param listener - Function to invoke when the specified event is
|
36 | * emitted
|
37 | * @param context - Optional context object to use when invoking the
|
38 | * listener
|
39 | */
|
40 | addListener(
|
41 | eventType: string,
|
42 | listener: (...args: any[]) => any,
|
43 | context?: any,
|
44 | ): EmitterSubscription;
|
45 |
|
46 | /**
|
47 | * Schedule a function to run after all interactions have completed.
|
48 | * Returns a cancellable
|
49 | */
|
50 | runAfterInteractions(task?: (() => any) | SimpleTask | PromiseTask): {
|
51 | then: (onfulfilled?: () => any, onrejected?: () => any) => Promise<any>;
|
52 | done: (...args: any[]) => any;
|
53 | cancel: () => void;
|
54 | };
|
55 |
|
56 | /**
|
57 | * Notify manager that an interaction has started.
|
58 | */
|
59 | createInteractionHandle(): Handle;
|
60 |
|
61 | /**
|
62 | * Notify manager that an interaction has completed.
|
63 | */
|
64 | clearInteractionHandle(handle: Handle): void;
|
65 |
|
66 | /**
|
67 | * A positive number will use setTimeout to schedule any tasks after
|
68 | * the eventLoopRunningTime hits the deadline value, otherwise all
|
69 | * tasks will be executed in one setImmediate batch (default).
|
70 | */
|
71 | setDeadline(deadline: number): void;
|
72 | }
|
73 |
|
74 | export const InteractionManager: InteractionManagerStatic;
|