-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
119 lines (97 loc) · 2.57 KB
/
types.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import { ReactNode, SyntheticEvent } from 'react'
import { StateMachine, Interpreter, State } from 'xstate'
// XState
export type TState = State<any, any, any, any>
export type TSend = TInterpreter['send']
type TInterpreter = Interpreter<any, any, any, any>
type TUseMachineReturn = [TState, TSend, TInterpreter]
// Common
type TFallback = ReactNode | ((state: TState) => ReactNode)
// Interpret
type TInterpretChildren =
| ReactNode
| ((state: TState, send: TSend, service: TInterpreter) => ReactNode)
export type TInterpretProps = {
children: TInterpretChildren
machine: StateMachine<any, any, any, any>
options?: any
machineId?: string
}
// MachineContext
export type TMachineContext = {
ref: {
current: TUseMachineReturn
}
[key: string]: {
current: TUseMachineReturn
}
}
// useContextMachine
export type TUseContextMachine = (
machineId?: string
) => TUseMachineReturn | undefined
// Matches & useMatches
type TMatchesShared = {
machineId?: string
context?: string
not?: boolean
}
type TMatchesValue = string | ((value: any, state: TState) => boolean)
type TMatchesChildren =
| ReactNode
| ((matches: boolean, state: TState) => ReactNode)
export type TMatchesProps = TMatchesShared & {
value: TMatchesValue
children?: TMatchesChildren
fallback?: TFallback
}
export type TUseMatches = (
value: TMatchesValue,
options?: TMatchesShared
) => boolean
// Send & useSend
export type TSendProps = {
as?: any
children?: ReactNode
machineId?: string
[key: string]: any
}
export type TType =
| string
| { [key: string]: any }
| ((
event: SyntheticEvent | undefined,
state: TState,
send: TSend
) => undefined | string | { [key: string]: any })
export type TUseSend = (
type: TType,
machineId?: string
) => ((event?: SyntheticEvent) => void) | undefined
// Value & useValue
type TValueShared = {
machineId?: string
context?: string
}
export type TValueProps = TValueShared & {
children?: (value: any, state: TState) => ReactNode
fallback?: ReactNode | ((state: TState) => ReactNode)
}
export type TUseValue = (
options?: TValueShared & {
parse?: (value: any, state: TState) => any
fallback?: any | ((state: TState) => any)
}
) => any
// Utilities
export type TGetResult = (value: any, path: string, regExp: RegExp) => any
export type TGet = (value: any, path: string) => any
export type TGetEventListener = (args: {
state: TState
send: TSend
type: TType
}) => (event?: SyntheticEvent) => void
export type TGetAttributeValue = (args: {
state: TState
value: string | ((state: TState) => any)
}) => any