@variousjs/various 4.0.1 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/loader.js +1 -1
- package/dist/loader.js.map +1 -1
- package/index.d.ts +84 -58
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -3,36 +3,59 @@ declare module '@variousjs/various' {
|
|
|
3
3
|
|
|
4
4
|
export { default as Nycticorax, Dispatch } from 'nycticorax'
|
|
5
5
|
|
|
6
|
-
type
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
export type ErrorType =
|
|
7
|
+
'LOADING_ERROR' |
|
|
8
|
+
'SUBMODULE_LOADING_ERROR' |
|
|
9
|
+
'NOT_DEFINED' |
|
|
10
|
+
'INVALID_COMPONENT' |
|
|
11
|
+
'SCRIPT_ERROR' |
|
|
12
|
+
'APP_ERROR' |
|
|
13
|
+
'INVALID_MODULE' |
|
|
14
|
+
'SUBMODULE_NOT_DEFINED' |
|
|
15
|
+
'SUBMODULE_SCRIPT_ERROR' |
|
|
16
|
+
'DISPATCH' |
|
|
17
|
+
'I18N'
|
|
18
|
+
|
|
19
|
+
export interface ComponentDefaultProps {
|
|
20
|
+
$silent?: boolean,
|
|
21
|
+
}
|
|
9
22
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
23
|
+
export interface VariousError extends Error {
|
|
24
|
+
type: ErrorType,
|
|
25
|
+
originalError: Error,
|
|
13
26
|
module?: string,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
27
|
+
name: string,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type ObjectAny = Record<string, any>
|
|
31
|
+
|
|
32
|
+
export interface ModuleDefined { name: string, module?: string }
|
|
33
|
+
|
|
34
|
+
interface Message { event: string, value: any, trigger: ModuleDefined }
|
|
35
|
+
|
|
36
|
+
type $dispatch = (args: ModuleDefined & {
|
|
37
|
+
action: string,
|
|
38
|
+
value: any,
|
|
39
|
+
}) => Promise<any>
|
|
40
|
+
type $postMessage = (event: string, value: any) => void
|
|
41
|
+
|
|
42
|
+
export type Intl = (key: string, params?: Record<string, string | number>) => string
|
|
18
43
|
|
|
19
44
|
export type ENV = 'development' | 'production'
|
|
20
45
|
|
|
21
|
-
export type
|
|
46
|
+
export type PublicAction = (value: any, trigger: ModuleDefined) => any
|
|
22
47
|
|
|
23
48
|
export type I18n = () => {
|
|
24
49
|
localeKey: string,
|
|
25
50
|
resources: Record<string, Record<string, string>>,
|
|
26
51
|
}
|
|
27
52
|
|
|
28
|
-
export interface Message { event: string, component: string, value?: any }
|
|
29
|
-
|
|
30
53
|
export type OnMessage = (message: Message) => void
|
|
31
54
|
|
|
32
55
|
export interface StaticProps {
|
|
33
56
|
$i18n?: I18n,
|
|
34
57
|
$onMessage?: OnMessage,
|
|
35
|
-
[x: string]:
|
|
58
|
+
[x: string]: PublicAction,
|
|
36
59
|
}
|
|
37
60
|
|
|
38
61
|
export type ComponentProps<
|
|
@@ -50,66 +73,56 @@ declare module '@variousjs/various' {
|
|
|
50
73
|
P extends object = {}
|
|
51
74
|
> = FC<ComponentProps<S, P>> & StaticProps
|
|
52
75
|
|
|
53
|
-
export
|
|
54
|
-
export interface ErrorProps<S extends object = {}> {
|
|
76
|
+
export interface ErrorNodeProps<S extends object = ObjectAny> {
|
|
55
77
|
$reload?: () => void,
|
|
56
|
-
$
|
|
57
|
-
$message?: string,
|
|
78
|
+
$error: VariousError,
|
|
58
79
|
$store: Readonly<S>,
|
|
59
80
|
}
|
|
60
|
-
export type ErrorNode<S extends object =
|
|
81
|
+
export type ErrorNode<S extends object = ObjectAny> = ComponentType<ErrorNodeProps<S>>
|
|
61
82
|
|
|
62
|
-
export interface
|
|
63
|
-
export type LoaderNode<S extends object =
|
|
83
|
+
export interface LoaderNodeProps<S extends object = ObjectAny> { $store: Readonly<S>}
|
|
84
|
+
export type LoaderNode<S extends object = ObjectAny> = ComponentType<LoaderNodeProps<S>>
|
|
64
85
|
|
|
65
|
-
type Dispatch<T extends object> = (
|
|
86
|
+
type Dispatch<T extends object = ObjectAny> = (
|
|
66
87
|
nycticorax: {
|
|
67
88
|
getStore: <K extends keyof T | undefined = undefined>(k?: K | undefined) =>
|
|
68
89
|
K extends keyof T ? T[K] : T,
|
|
69
90
|
emit: (next: Partial<T>) => void,
|
|
70
91
|
},
|
|
71
92
|
value: any,
|
|
72
|
-
trigger:
|
|
93
|
+
trigger: ModuleDefined,
|
|
73
94
|
) => Promise<any>
|
|
74
95
|
|
|
75
|
-
export type Actions<S extends object = {}> = Record<string, Dispatch<S>>
|
|
76
|
-
|
|
77
96
|
interface MessageEventArgs {
|
|
78
|
-
trigger:
|
|
97
|
+
trigger: ModuleDefined,
|
|
79
98
|
event: string,
|
|
80
|
-
value
|
|
99
|
+
value: any,
|
|
81
100
|
}
|
|
82
101
|
type MessageEventRes = boolean | Omit<MessageEventArgs, 'trigger'>
|
|
83
102
|
interface DispatchEventArgs {
|
|
84
|
-
target:
|
|
85
|
-
trigger:
|
|
86
|
-
|
|
87
|
-
value
|
|
103
|
+
target: ModuleDefined,
|
|
104
|
+
trigger: ModuleDefined,
|
|
105
|
+
action: string,
|
|
106
|
+
value: any,
|
|
88
107
|
}
|
|
89
108
|
type DispatchEventRes = boolean | Omit<DispatchEventArgs, 'trigger'>
|
|
90
|
-
interface LoadEventArgs {
|
|
91
|
-
name: string,
|
|
109
|
+
interface LoadEventArgs extends ModuleDefined {
|
|
92
110
|
loadStart: number,
|
|
93
111
|
loadEnd: number,
|
|
94
|
-
duration: number,
|
|
95
112
|
beenLoaded: boolean,
|
|
96
113
|
}
|
|
97
|
-
|
|
98
|
-
name: string,
|
|
99
|
-
errorType: ErrorType | 'dispatch' | 'i18n',
|
|
100
|
-
errorMessage: string,
|
|
101
|
-
}
|
|
114
|
+
|
|
102
115
|
export type MessageEvent = (e: MessageEventArgs) => Promise<MessageEventRes> | MessageEventRes
|
|
103
116
|
export type DispatchEvent = (e: DispatchEventArgs) => Promise<DispatchEventRes> | DispatchEventRes
|
|
104
117
|
export type LoadEvent = (e: LoadEventArgs) => void
|
|
105
|
-
export type ErrorEvent = (e:
|
|
118
|
+
export type ErrorEvent = (e: VariousError) => void
|
|
106
119
|
|
|
107
|
-
export interface App<S extends object =
|
|
120
|
+
export interface App<S extends object = ObjectAny> {
|
|
108
121
|
store?: readonly S,
|
|
109
122
|
Error?: ErrorNode<S>,
|
|
110
123
|
Loader?: LoaderNode<S>,
|
|
111
|
-
actions?:
|
|
112
|
-
Container: ComponentType
|
|
124
|
+
actions?: Record<string, Dispatch<S>>,
|
|
125
|
+
Container: ComponentType<any>,
|
|
113
126
|
middlewares?: {
|
|
114
127
|
onLoad?: LoadEvent,
|
|
115
128
|
onError?: ErrorEvent,
|
|
@@ -130,23 +143,36 @@ declare module '@variousjs/various' {
|
|
|
130
143
|
earlyParallelComponents?: string[],
|
|
131
144
|
}
|
|
132
145
|
|
|
133
|
-
export function createComponent<
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
146
|
+
export function createComponent<
|
|
147
|
+
S extends object = ObjectAny,
|
|
148
|
+
P extends object = ObjectAny
|
|
149
|
+
>(
|
|
150
|
+
config: ModuleDefined & { url?: string },
|
|
151
|
+
storeKeys?: (keyof S)[],
|
|
152
|
+
): ComponentType<ComponentDefaultProps & P>
|
|
153
|
+
|
|
154
|
+
export function createModule<T = unknown> (params: ModuleDefined & {
|
|
155
|
+
url?: string,
|
|
156
|
+
}): Promise<T>
|
|
157
|
+
|
|
158
|
+
export function renderComponent<P extends object = ObjectAny>(params: ModuleDefined & {
|
|
159
|
+
url?: string,
|
|
160
|
+
props?: P & ComponentDefaultProps,
|
|
161
|
+
target: Element | null,
|
|
162
|
+
onMounted?: () => void,
|
|
163
|
+
}): () => void
|
|
140
164
|
|
|
141
|
-
export const
|
|
142
|
-
export const getMountedComponents: () =>
|
|
143
|
-
export const
|
|
144
|
-
export const onComponentMounted: (
|
|
165
|
+
export const isModuleLoaded: (moduleDefined: ModuleDefined) => boolean
|
|
166
|
+
export const getMountedComponents: () => ModuleDefined[]
|
|
167
|
+
export const preloadPackages: (name: string | string[]) => Promise<void>
|
|
168
|
+
export const onComponentMounted: (
|
|
169
|
+
name: ModuleDefined | ModuleDefined[], callback: () => void
|
|
170
|
+
) => () => void
|
|
145
171
|
|
|
146
172
|
export const getEnv: () => ENV
|
|
147
|
-
export function getConfig<C extends object =
|
|
148
|
-
export function getStore<S extends object =
|
|
173
|
+
export function getConfig<C extends object = ObjectAny>(): C
|
|
174
|
+
export function getStore<S extends object = ObjectAny>(): S
|
|
149
175
|
|
|
150
|
-
export const createDispatch: (
|
|
151
|
-
export const createPostMessage: (
|
|
176
|
+
export const createDispatch: (m: ModuleDefined) => $dispatch
|
|
177
|
+
export const createPostMessage: (m: ModuleDefined) => $postMessage
|
|
152
178
|
}
|