This repository has been archived by the owner on Apr 13, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interfaces.ts
80 lines (75 loc) · 1.63 KB
/
interfaces.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
import {Stream} from 'xstream';
/**
* An action handler executes an action.
*/
export interface ActionHandler<I, O> {
/**
* The handler.
* @param action the action
* @return an optional output which can be embedded within a Promise
*/
(action: Action<I>): O | Promise<O>
}
/**
* The map of action handlers.
* To be handled, the {@link Action.type} of the {@link Action} must match the key of the {@link ActionHandlers} object.
*/
export type ActionHandlers<I, O> = {
[k: string]: ActionHandler<I, O>
}
/**
* An action is a message which will be handled by an {@link ActionHandler}.
*/
export interface Action<I> {
/**
* The type of the message.
*/
type: string
/**
* The optional payload.
*/
payload?: I
/**
* The category is used to select action's results via {@link ActionsSource.select}.
*/
category?: string
/**
* The namespace is used internally to manage the isolation.
* c.f. https://cycle.js.org/components.html#components-isolating-multiple-instances
*/
namespace?: Array<string>
}
/**
* An action result is used internally to build the source part.
*/
export interface ActionResult<I, O> {
/**
* The request.
*/
request: Action<I>
/**
* The response related to the handled action.
*/
response?: O
/**
* The error raised during the handling of the action.
*/
error?: Error
}
/**
* A subset of results.
*/
export interface SelectedResults<I, O> {
/**
* The stream of results.
*/
result$: Stream<ActionResult<I, O>>
/**
* The stream of responses.
*/
response$: Stream<O>
/**
* The stream of errors.
*/
error$: Stream<Error>
}