-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlast.dts.ref.d.ts
68 lines (61 loc) · 2.01 KB
/
last.dts.ref.d.ts
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/// <reference types="react" />
import React from 'react'
type Status = 'in_progress' | 'ready'
type UseWatcher = (done: () => void) => void
/**
* createSingleton hook returns the necessary methods to make your service
* (singleton) works within React.
*
* - watch: Watches the changes that are being made inside the singleton.
* A "done" method is provided, you must call it when the necessary
* data is updated so that, React will be notified. This function
* supports sync and async calls.
*
* - setClass: Set the Singleton Class. You must pass your singleton as parameter to this function.
*/
declare function createSingleton(): {
watch: (method: UseWatcher) => void
setClass<C>(classValue: C): void
}
/**
* This hook will let the app know the current status of a specific Singleton's process.
* Returns "in_progress" when Singleton's values are being changed and "ready"
* when it has been updated.
*
* @param singletonClass Singleton class
*/
declare function useSingletonStatus<C>(singletonClass: C): Status
/**
* Re-render with new singleton props when the singleton props are updated
* @param singletonClass Singleton class
*/
declare function useReRenderOnUpdate<C>(singletonClass: C): void
/**
* This hook lets the app know when the Singleton is not using default
* (data stored at the moment this hook was used) props any more.
* Returns true or false.
*
* @param singletonClass Singleton class
* @param debounceDelay The debounce delay used to define if data was updated (default: 500)
*/
declare function useWasDataUpdated<C>(
singletonClass: C,
debounceDelay?: number
): boolean
/**
* Re-render with new singleton props when the singleton props are updated
* @param Component React component
* @param singletonClass Singleton class
*/
declare function withSingleton<T, C>(
Component: React.ComponentType<T> | React.FC<T>,
singletonClass: C
): (props: T) => JSX.Element
export {
Status,
createSingleton,
useSingletonStatus,
useReRenderOnUpdate,
useWasDataUpdated,
withSingleton,
}