forked from fusionjs/fusion-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflow.js
77 lines (68 loc) · 2.01 KB
/
flow.js
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
/* @flow */
import type {Context as KoaContext} from 'koa';
declare var __NODE__: Boolean;
declare var __BROWSER__: Boolean;
type ExtractReturnType = <V>(() => V) => V;
type ExtendedKoaContext = KoaContext & {memoized: Map<Object, mixed>};
type aliaser<Token> = {
alias: (sourceToken: Token, destToken: Token) => aliaser<*>,
};
declare type Token<T> = {
(): T,
optional: () => void | T,
};
declare type SSRContext = {
element: any,
template: {
htmlAttrs: Object,
title: string,
head: Array<string>,
body: Array<string>,
},
} & ExtendedKoaContext;
declare type Context = SSRContext | ExtendedKoaContext;
declare type FusionPlugin<Deps, Service> = {
deps?: Deps,
provides?: (Deps: $ObjMap<Deps, ExtractReturnType>) => Service,
middleware?: (
Deps: $ObjMap<Deps, ExtractReturnType>,
Service: Service
) => Middleware,
cleanup?: (service: Service) => Promise<any>,
};
declare type Middleware = (
ctx: Context,
next: () => Promise<void>
) => Promise<*>;
type cleanupFn = (thing: any) => Promise<any>;
declare class FusionApp {
constructor<Element>(element: Element, render: (Element) => any): FusionApp;
cleanups: Array<cleanupFn>;
registered: Map<any, any>;
plugins: Array<any>;
renderer: any;
cleanup(): Promise<any>;
enhance<Token, Deps>(
token: Token,
enhancer: (
item: $Call<ExtractReturnType, Token>
) => FusionPlugin<Deps, $Call<ExtractReturnType, Token>>
): void;
enhance<Token>(token: Token, enhancer: (token: Token) => Token): void;
register<Deps, Provides>(Plugin: FusionPlugin<Deps, Provides>): aliaser<*>;
register<Token, Deps>(
token: Token,
Plugin: FusionPlugin<Deps, $Call<ExtractReturnType, Token>>
): aliaser<*>;
register<Token: Object>(
token: Token,
val: $Call<ExtractReturnType, Token>
): aliaser<*>;
middleware<Deps>(
deps: Deps,
middleware: (Deps: $ObjMap<Deps, ExtractReturnType>) => Middleware
): void;
middleware(middleware: Middleware): void;
callback(): () => Promise<void>;
resolve(): void;
}