-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathIViewLocker.ts
More file actions
54 lines (48 loc) · 1.46 KB
/
IViewLocker.ts
File metadata and controls
54 lines (48 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { isObject } from './isObject.ts';
/**
* Interface for managing view restoration state to prevent early access to an inconsistent view
* or concurrent restoration by another process.
*/
export interface IViewLocker {
/**
* Indicates whether the view is fully restored and ready to accept new event projections.
*/
ready: boolean;
/**
* Locks the view to prevent external read/write operations.
*
* @returns `true` if the lock is successfully acquired, `false` otherwise.
*/
lock(): Promise<boolean> | boolean;
/**
* Unlocks the view, allowing external read/write operations to resume.
*/
unlock(): Promise<void> | void;
/**
* Waits until the view is fully restored and ready to accept new events.
*
* @param eventType The event type to listen for (`"ready"`).
* @returns A promise that resolves when the view is ready.
*/
once(eventType: 'ready'): Promise<void>;
}
/**
* Checks if a given object conforms to the `IViewLocker` interface.
*
* @param view The object to check.
* @returns `true` if the object implements `IViewLocker`, `false` otherwise.
*/
export const isViewLocker = (view: unknown): view is IViewLocker =>
(
isObject(view)
&& 'ready' in view
&& 'lock' in view
&& 'unlock' in view
&& 'once' in view
) || (
typeof view === 'function'
&& typeof (view as any).lock === 'function'
&& typeof (view as any).unlock === 'function'
&& typeof (view as any).once === 'function'
&& (view as any).ready !== undefined
);