-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
69 lines (60 loc) · 2.06 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
export type LitLikeElement = {
requestUpdate: () => void
dispatchEvent: (e: Event) => boolean
updateComplete: Promise<void | boolean>
}
export type UpdateableLitLikeElement = {
updated(_?: any): void
}
type States = {
index: number,
count: number,
states: InjectableState<any>[]
reducers: Reduce<any>[]
workflows: Workflow[]
}
export type DecoratedLitLikeElement = LitLikeElement & {
__registered_states: States
}
export type Reducer<T> = (state: T) => {[action: string]: (payload?: any | unknown | undefined) => Promise<T>}
export type StateOptions = {
updateDefault?: boolean
}
export type ReducerOptions = StateOptions & {
dispatchEvent?: boolean
}
export interface State<T> {
/**
* @deprecated The method should not be used. Use `get` or `value` instead.
*/
getState: () => T
/**
* @deprecated The method should not be used. Use `set` or `value` instead.
*/
publish: (update: T) => void
get: () => T
set: (update: T) => Promise<void>
value: T
subscribe: (onChange: (state: T) => Promise<void>) => void
}
export interface InjectableState<T> extends State<T> {
inject: (update: T) => void,
}
export type Reduce<T> = {
get: () => T
set: <T>(action: string, data?: T) => Promise<T>
subscribe: (onChange: (action: string, state: T) => void) => void
when: (action: string, onChange: (state: T) => void) => void
dispatch: <T>(action: string, data?: T) => Promise<T>
}
export type WorkflowHistory = { type: string, args: unknown[] }
export type Workflow = {
addActivity: (activity: string, data?: unknown) => Promise<void>
addCompensation: (activity: string, data?: unknown) => void
addSideeffect: (activity: string, sideeffect: (data?: unknown) => Promise<unknown>) => void
projections: (key: string) => any
after: (timeout: Date, unlessActivity: WorkflowHistory, execute: () => Promise<unknown>) => void
compensate: () => Promise<unknown>
history: () => WorkflowHistory[]
plan: <T>(plan: {[entity: string]: () => Promise<T>}) => Promise<T | null>
}