@shuvi/platform-shared 1.0.0-rc.4 → 1.0.0-rc.5
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/esm/shared/application.d.ts +10 -63
- package/esm/shared/application.js +39 -10
- package/esm/shared/applicationTypes.d.ts +6 -8
- package/esm/shared/helper/getAppData.d.ts +1 -4
- package/esm/shared/helper/getAppData.js +0 -1
- package/esm/shared/index.d.ts +1 -0
- package/esm/shared/index.js +1 -0
- package/esm/shared/loader/index.d.ts +0 -1
- package/esm/shared/loader/index.js +0 -1
- package/esm/shared/models/error.d.ts +2 -2
- package/esm/shared/models/error.js +2 -2
- package/esm/shared/models/loader.d.ts +13 -0
- package/esm/shared/models/loader.js +24 -0
- package/lib/shared/application.d.ts +10 -63
- package/lib/shared/application.js +39 -10
- package/lib/shared/applicationTypes.d.ts +6 -8
- package/lib/shared/helper/getAppData.d.ts +1 -4
- package/lib/shared/helper/getAppData.js +0 -1
- package/lib/shared/index.d.ts +1 -0
- package/lib/shared/index.js +3 -1
- package/lib/shared/loader/index.d.ts +0 -1
- package/lib/shared/loader/index.js +0 -1
- package/lib/shared/models/error.d.ts +2 -2
- package/lib/shared/models/error.js +2 -2
- package/lib/shared/models/loader.d.ts +13 -0
- package/lib/shared/models/loader.js +27 -0
- package/package.json +9 -9
- package/esm/shared/loader/loaderManager.d.ts +0 -16
- package/esm/shared/loader/loaderManager.js +0 -49
- package/lib/shared/loader/loaderManager.d.ts +0 -16
- package/lib/shared/loader/loaderManager.js +0 -53
|
@@ -1,78 +1,25 @@
|
|
|
1
1
|
import { IRouter, IPageRouteRecord } from './routerTypes';
|
|
2
|
-
import { IStoreManager, IApplication, IAppContext, IApplicationOptions, IRerenderConfig } from './applicationTypes';
|
|
2
|
+
import { IStoreManager, IApplication, IAppContext, IApplicationOptions, IRerenderConfig, IError } from './applicationTypes';
|
|
3
3
|
export declare class Application {
|
|
4
|
-
private _error;
|
|
5
4
|
private _router;
|
|
6
5
|
private _appComponent;
|
|
7
6
|
private _pluginManager;
|
|
8
7
|
private _context;
|
|
9
|
-
private
|
|
8
|
+
private _store;
|
|
9
|
+
private _error;
|
|
10
|
+
private _loader;
|
|
10
11
|
constructor(options: IApplicationOptions);
|
|
11
12
|
get router(): IRouter<IPageRouteRecord>;
|
|
12
13
|
get context(): IAppContext;
|
|
13
14
|
get pluginManager(): import("@shuvi/hook").HookManager<import("./lifecycle").BuiltInRuntimePluginHooks, void, import("@shuvi/runtime").CustomRuntimePluginHooks>;
|
|
14
15
|
get appComponent(): any;
|
|
15
|
-
get error():
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
$actions: {
|
|
21
|
-
setError: (payload?: import("./applicationTypes").IError | undefined) => import("@shuvi/redox").Action<import("./applicationTypes").IError | undefined>;
|
|
22
|
-
} & {
|
|
23
|
-
error: (payload?: import("./applicationTypes").IError | undefined) => void;
|
|
24
|
-
clear: () => void;
|
|
25
|
-
} & {
|
|
26
|
-
[X: string]: never;
|
|
27
|
-
[X: number]: never;
|
|
28
|
-
[X: symbol]: never;
|
|
29
|
-
};
|
|
30
|
-
$views: import("@shuvi/redox").RedoxViews<({
|
|
31
|
-
getError(): import("./applicationTypes").IError | undefined;
|
|
32
|
-
hasError(): boolean;
|
|
33
|
-
} & ThisType<import("./applicationTypes").IErrorState & {
|
|
34
|
-
$state: import("./applicationTypes").IErrorState;
|
|
35
|
-
} & import("@shuvi/redox").RedoxViews<{
|
|
36
|
-
getError(): import("./applicationTypes").IError | undefined;
|
|
37
|
-
hasError(): boolean;
|
|
38
|
-
}> & {
|
|
39
|
-
$dep: {} & {} & {};
|
|
40
|
-
}>) | undefined>;
|
|
41
|
-
$createSelector: <TReturn>(selector: import("@shuvi/redox").ISelector<import("@shuvi/redox").Model<"error", import("./applicationTypes").IErrorState, {}, {
|
|
42
|
-
setError(_state: import("./applicationTypes").IErrorState, error?: import("./applicationTypes").IError | undefined): {
|
|
43
|
-
error: import("./applicationTypes").IError | undefined;
|
|
44
|
-
};
|
|
45
|
-
}, {
|
|
46
|
-
error(payload?: import("./applicationTypes").IError | undefined): void;
|
|
47
|
-
clear(): void;
|
|
48
|
-
}, {
|
|
49
|
-
getError(): import("./applicationTypes").IError | undefined;
|
|
50
|
-
hasError(): boolean;
|
|
51
|
-
}>, TReturn>) => (() => TReturn) & {
|
|
52
|
-
clearCache: () => void;
|
|
53
|
-
};
|
|
54
|
-
} & import("@shuvi/redox").RedoxViews<{
|
|
55
|
-
getError(): import("./applicationTypes").IError | undefined;
|
|
56
|
-
hasError(): boolean;
|
|
57
|
-
} & ThisType<import("./applicationTypes").IErrorState & {
|
|
58
|
-
$state: import("./applicationTypes").IErrorState;
|
|
59
|
-
} & import("@shuvi/redox").RedoxViews<{
|
|
60
|
-
getError(): import("./applicationTypes").IError | undefined;
|
|
61
|
-
hasError(): boolean;
|
|
62
|
-
}> & {
|
|
63
|
-
$dep: {} & {} & {};
|
|
64
|
-
}>> & {
|
|
65
|
-
setError: (payload?: import("./applicationTypes").IError | undefined) => import("@shuvi/redox").Action<import("./applicationTypes").IError | undefined>;
|
|
66
|
-
} & {
|
|
67
|
-
error: (payload?: import("./applicationTypes").IError | undefined) => void;
|
|
68
|
-
clear: () => void;
|
|
69
|
-
} & {
|
|
70
|
-
[X: string]: never;
|
|
71
|
-
[X: number]: never;
|
|
72
|
-
[X: symbol]: never;
|
|
73
|
-
};
|
|
16
|
+
get error(): IError | undefined;
|
|
17
|
+
setError(err: IError): void;
|
|
18
|
+
clearError(): void;
|
|
19
|
+
getLoadersData(): Record<string, any>;
|
|
20
|
+
setLoadersData(datas: Record<string, any>): void;
|
|
74
21
|
init(): Promise<void>;
|
|
75
|
-
get
|
|
22
|
+
get store(): IStoreManager;
|
|
76
23
|
updateComponents({ AppComponent }?: IRerenderConfig): Promise<void>;
|
|
77
24
|
dispose(): Promise<void>;
|
|
78
25
|
private _initPlugin;
|
|
@@ -11,12 +11,14 @@ import { getManager } from './lifecycle';
|
|
|
11
11
|
import { initPlugins } from './lifecycle';
|
|
12
12
|
import { redox } from '@shuvi/redox';
|
|
13
13
|
import { errorModel } from './models/error';
|
|
14
|
+
import { loaderModel } from './models/loader';
|
|
14
15
|
export class Application {
|
|
15
16
|
constructor(options) {
|
|
16
17
|
this._router = options.router;
|
|
17
18
|
this._context = {};
|
|
18
|
-
this.
|
|
19
|
-
this._error = this.
|
|
19
|
+
this._store = redox({ initialState: options.initialState });
|
|
20
|
+
this._error = this._store.get(errorModel);
|
|
21
|
+
this._loader = this._store.get(loaderModel);
|
|
20
22
|
this._appComponent = options.AppComponent;
|
|
21
23
|
this._pluginManager = getManager();
|
|
22
24
|
initPlugins(this._pluginManager, options.plugins || []);
|
|
@@ -34,7 +36,19 @@ export class Application {
|
|
|
34
36
|
return this._appComponent;
|
|
35
37
|
}
|
|
36
38
|
get error() {
|
|
37
|
-
return this._error;
|
|
39
|
+
return this._error.errorObject;
|
|
40
|
+
}
|
|
41
|
+
setError(err) {
|
|
42
|
+
this._error.set(err);
|
|
43
|
+
}
|
|
44
|
+
clearError() {
|
|
45
|
+
this._error.clear();
|
|
46
|
+
}
|
|
47
|
+
getLoadersData() {
|
|
48
|
+
return this._loader.getAllData;
|
|
49
|
+
}
|
|
50
|
+
setLoadersData(datas) {
|
|
51
|
+
this._loader.setDatas(datas);
|
|
38
52
|
}
|
|
39
53
|
init() {
|
|
40
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -44,8 +58,8 @@ export class Application {
|
|
|
44
58
|
this._router.init();
|
|
45
59
|
});
|
|
46
60
|
}
|
|
47
|
-
get
|
|
48
|
-
return this.
|
|
61
|
+
get store() {
|
|
62
|
+
return this._store;
|
|
49
63
|
}
|
|
50
64
|
updateComponents({ AppComponent } = {}) {
|
|
51
65
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -76,12 +90,27 @@ export class Application {
|
|
|
76
90
|
});
|
|
77
91
|
}
|
|
78
92
|
getPublicAPI() {
|
|
93
|
+
const self = this;
|
|
79
94
|
return {
|
|
80
|
-
context:
|
|
81
|
-
router:
|
|
82
|
-
appComponent:
|
|
83
|
-
|
|
84
|
-
error
|
|
95
|
+
context: self._context,
|
|
96
|
+
router: self._router,
|
|
97
|
+
appComponent: self._appComponent,
|
|
98
|
+
store: self._store,
|
|
99
|
+
get error() {
|
|
100
|
+
return self.error;
|
|
101
|
+
},
|
|
102
|
+
setError(err) {
|
|
103
|
+
self.setError(err);
|
|
104
|
+
},
|
|
105
|
+
clearError() {
|
|
106
|
+
self.clearError();
|
|
107
|
+
},
|
|
108
|
+
getLoadersData() {
|
|
109
|
+
return self.getLoadersData();
|
|
110
|
+
},
|
|
111
|
+
setLoadersData(datas) {
|
|
112
|
+
self.setLoadersData(datas);
|
|
113
|
+
}
|
|
85
114
|
};
|
|
86
115
|
}
|
|
87
116
|
}
|
|
@@ -24,18 +24,16 @@ export interface IErrorState {
|
|
|
24
24
|
export declare type IAppState = {
|
|
25
25
|
error?: IErrorState;
|
|
26
26
|
};
|
|
27
|
-
export interface IErrorManager {
|
|
28
|
-
getError: IError | undefined;
|
|
29
|
-
error: (err: IError) => void;
|
|
30
|
-
clear: () => void;
|
|
31
|
-
hasError: boolean;
|
|
32
|
-
}
|
|
33
27
|
export interface IApplication {
|
|
34
28
|
readonly context: IAppContext;
|
|
35
29
|
readonly router: IRouter<IPageRouteRecord>;
|
|
36
30
|
readonly appComponent: any;
|
|
37
|
-
readonly
|
|
38
|
-
readonly
|
|
31
|
+
readonly store: IStoreManager;
|
|
32
|
+
readonly error: IError | undefined;
|
|
33
|
+
setError(err: IError): void;
|
|
34
|
+
clearError(): void;
|
|
35
|
+
getLoadersData(): Record<string, any>;
|
|
36
|
+
setLoadersData(datas: Record<string, any>): void;
|
|
39
37
|
}
|
|
40
38
|
export interface IApplicationOptions {
|
|
41
39
|
router: IRouter;
|
|
@@ -5,13 +5,10 @@ export declare type IData = {
|
|
|
5
5
|
export declare type IAppData<Data = {}, appState = any> = {
|
|
6
6
|
ssr: boolean;
|
|
7
7
|
runtimeConfig?: Record<string, string>;
|
|
8
|
+
appState?: appState;
|
|
8
9
|
pageData?: {
|
|
9
10
|
[key: string]: any;
|
|
10
11
|
};
|
|
11
|
-
loadersData?: {
|
|
12
|
-
[x: string]: any;
|
|
13
|
-
};
|
|
14
|
-
appState?: appState;
|
|
15
12
|
filesByRoutId: Record<string, string[]>;
|
|
16
13
|
publicPath: string;
|
|
17
14
|
} & {
|
package/esm/shared/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from './router';
|
|
|
4
4
|
export * from './response';
|
|
5
5
|
export * from './loader';
|
|
6
6
|
export { errorModel } from './models/error';
|
|
7
|
+
export { loaderModel } from './models/loader';
|
|
7
8
|
export * from './applicationTypes';
|
|
8
9
|
export type { Application } from './application';
|
|
9
10
|
export type { IRuntimeConfig } from './runtimeConfigTypes';
|
package/esm/shared/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export * from './router';
|
|
|
4
4
|
export * from './response';
|
|
5
5
|
export * from './loader';
|
|
6
6
|
export { errorModel } from './models/error';
|
|
7
|
+
export { loaderModel } from './models/loader';
|
|
7
8
|
export * from './applicationTypes';
|
|
8
9
|
export {
|
|
9
10
|
// fix createRuntimePlugin is not portable end
|
|
@@ -4,10 +4,10 @@ export declare const errorModel: import("@shuvi/redox").Model<"error", IErrorSta
|
|
|
4
4
|
error: IError | undefined;
|
|
5
5
|
};
|
|
6
6
|
}, {
|
|
7
|
-
|
|
7
|
+
set(payload?: IError): void;
|
|
8
8
|
clear(): void;
|
|
9
9
|
}, {
|
|
10
|
-
|
|
10
|
+
errorObject(): IError | undefined;
|
|
11
11
|
hasError(): boolean;
|
|
12
12
|
}>;
|
|
13
13
|
export declare type ErrorModel = typeof errorModel;
|
|
@@ -12,7 +12,7 @@ export const errorModel = defineModel({
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
actions: {
|
|
15
|
-
|
|
15
|
+
set(payload) {
|
|
16
16
|
this.setError(payload || SHUVI_ERROR.APP_ERROR);
|
|
17
17
|
},
|
|
18
18
|
clear() {
|
|
@@ -22,7 +22,7 @@ export const errorModel = defineModel({
|
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
views: {
|
|
25
|
-
|
|
25
|
+
errorObject() {
|
|
26
26
|
return this.error;
|
|
27
27
|
},
|
|
28
28
|
hasError() {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface LoaderState {
|
|
2
|
+
dataByRouteId: Record<string, any>;
|
|
3
|
+
}
|
|
4
|
+
export declare const loaderModel: import("@shuvi/redox").Model<"loader", LoaderState, {}, {
|
|
5
|
+
setDatas(state: LoaderState, newData: Record<string, any>): {
|
|
6
|
+
dataByRouteId: {
|
|
7
|
+
[x: string]: any;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
}, import("@shuvi/redox").RedoxActions, {
|
|
11
|
+
getAllData(): Record<string, any>;
|
|
12
|
+
}>;
|
|
13
|
+
export declare type LoaderModel = typeof loaderModel;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { defineModel } from '@shuvi/redox';
|
|
2
|
+
const initState = {
|
|
3
|
+
dataByRouteId: {}
|
|
4
|
+
};
|
|
5
|
+
export const loaderModel = defineModel({
|
|
6
|
+
name: 'loader',
|
|
7
|
+
state: initState,
|
|
8
|
+
reducers: {
|
|
9
|
+
setDatas(state, newData) {
|
|
10
|
+
return Object.assign(Object.assign({}, state), { dataByRouteId: Object.assign(Object.assign({}, state.dataByRouteId), newData) });
|
|
11
|
+
}
|
|
12
|
+
// clearDatas(state) {
|
|
13
|
+
// return {
|
|
14
|
+
// ...state,
|
|
15
|
+
// dataByRouteId: {}
|
|
16
|
+
// };
|
|
17
|
+
// }
|
|
18
|
+
},
|
|
19
|
+
views: {
|
|
20
|
+
getAllData() {
|
|
21
|
+
return this.dataByRouteId;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
});
|
|
@@ -1,78 +1,25 @@
|
|
|
1
1
|
import { IRouter, IPageRouteRecord } from './routerTypes';
|
|
2
|
-
import { IStoreManager, IApplication, IAppContext, IApplicationOptions, IRerenderConfig } from './applicationTypes';
|
|
2
|
+
import { IStoreManager, IApplication, IAppContext, IApplicationOptions, IRerenderConfig, IError } from './applicationTypes';
|
|
3
3
|
export declare class Application {
|
|
4
|
-
private _error;
|
|
5
4
|
private _router;
|
|
6
5
|
private _appComponent;
|
|
7
6
|
private _pluginManager;
|
|
8
7
|
private _context;
|
|
9
|
-
private
|
|
8
|
+
private _store;
|
|
9
|
+
private _error;
|
|
10
|
+
private _loader;
|
|
10
11
|
constructor(options: IApplicationOptions);
|
|
11
12
|
get router(): IRouter<IPageRouteRecord>;
|
|
12
13
|
get context(): IAppContext;
|
|
13
14
|
get pluginManager(): import("@shuvi/hook").HookManager<import("./lifecycle").BuiltInRuntimePluginHooks, void, import("@shuvi/runtime").CustomRuntimePluginHooks>;
|
|
14
15
|
get appComponent(): any;
|
|
15
|
-
get error():
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
$actions: {
|
|
21
|
-
setError: (payload?: import("./applicationTypes").IError | undefined) => import("@shuvi/redox").Action<import("./applicationTypes").IError | undefined>;
|
|
22
|
-
} & {
|
|
23
|
-
error: (payload?: import("./applicationTypes").IError | undefined) => void;
|
|
24
|
-
clear: () => void;
|
|
25
|
-
} & {
|
|
26
|
-
[X: string]: never;
|
|
27
|
-
[X: number]: never;
|
|
28
|
-
[X: symbol]: never;
|
|
29
|
-
};
|
|
30
|
-
$views: import("@shuvi/redox").RedoxViews<({
|
|
31
|
-
getError(): import("./applicationTypes").IError | undefined;
|
|
32
|
-
hasError(): boolean;
|
|
33
|
-
} & ThisType<import("./applicationTypes").IErrorState & {
|
|
34
|
-
$state: import("./applicationTypes").IErrorState;
|
|
35
|
-
} & import("@shuvi/redox").RedoxViews<{
|
|
36
|
-
getError(): import("./applicationTypes").IError | undefined;
|
|
37
|
-
hasError(): boolean;
|
|
38
|
-
}> & {
|
|
39
|
-
$dep: {} & {} & {};
|
|
40
|
-
}>) | undefined>;
|
|
41
|
-
$createSelector: <TReturn>(selector: import("@shuvi/redox").ISelector<import("@shuvi/redox").Model<"error", import("./applicationTypes").IErrorState, {}, {
|
|
42
|
-
setError(_state: import("./applicationTypes").IErrorState, error?: import("./applicationTypes").IError | undefined): {
|
|
43
|
-
error: import("./applicationTypes").IError | undefined;
|
|
44
|
-
};
|
|
45
|
-
}, {
|
|
46
|
-
error(payload?: import("./applicationTypes").IError | undefined): void;
|
|
47
|
-
clear(): void;
|
|
48
|
-
}, {
|
|
49
|
-
getError(): import("./applicationTypes").IError | undefined;
|
|
50
|
-
hasError(): boolean;
|
|
51
|
-
}>, TReturn>) => (() => TReturn) & {
|
|
52
|
-
clearCache: () => void;
|
|
53
|
-
};
|
|
54
|
-
} & import("@shuvi/redox").RedoxViews<{
|
|
55
|
-
getError(): import("./applicationTypes").IError | undefined;
|
|
56
|
-
hasError(): boolean;
|
|
57
|
-
} & ThisType<import("./applicationTypes").IErrorState & {
|
|
58
|
-
$state: import("./applicationTypes").IErrorState;
|
|
59
|
-
} & import("@shuvi/redox").RedoxViews<{
|
|
60
|
-
getError(): import("./applicationTypes").IError | undefined;
|
|
61
|
-
hasError(): boolean;
|
|
62
|
-
}> & {
|
|
63
|
-
$dep: {} & {} & {};
|
|
64
|
-
}>> & {
|
|
65
|
-
setError: (payload?: import("./applicationTypes").IError | undefined) => import("@shuvi/redox").Action<import("./applicationTypes").IError | undefined>;
|
|
66
|
-
} & {
|
|
67
|
-
error: (payload?: import("./applicationTypes").IError | undefined) => void;
|
|
68
|
-
clear: () => void;
|
|
69
|
-
} & {
|
|
70
|
-
[X: string]: never;
|
|
71
|
-
[X: number]: never;
|
|
72
|
-
[X: symbol]: never;
|
|
73
|
-
};
|
|
16
|
+
get error(): IError | undefined;
|
|
17
|
+
setError(err: IError): void;
|
|
18
|
+
clearError(): void;
|
|
19
|
+
getLoadersData(): Record<string, any>;
|
|
20
|
+
setLoadersData(datas: Record<string, any>): void;
|
|
74
21
|
init(): Promise<void>;
|
|
75
|
-
get
|
|
22
|
+
get store(): IStoreManager;
|
|
76
23
|
updateComponents({ AppComponent }?: IRerenderConfig): Promise<void>;
|
|
77
24
|
dispose(): Promise<void>;
|
|
78
25
|
private _initPlugin;
|
|
@@ -14,12 +14,14 @@ const lifecycle_1 = require("./lifecycle");
|
|
|
14
14
|
const lifecycle_2 = require("./lifecycle");
|
|
15
15
|
const redox_1 = require("@shuvi/redox");
|
|
16
16
|
const error_1 = require("./models/error");
|
|
17
|
+
const loader_1 = require("./models/loader");
|
|
17
18
|
class Application {
|
|
18
19
|
constructor(options) {
|
|
19
20
|
this._router = options.router;
|
|
20
21
|
this._context = {};
|
|
21
|
-
this.
|
|
22
|
-
this._error = this.
|
|
22
|
+
this._store = (0, redox_1.redox)({ initialState: options.initialState });
|
|
23
|
+
this._error = this._store.get(error_1.errorModel);
|
|
24
|
+
this._loader = this._store.get(loader_1.loaderModel);
|
|
23
25
|
this._appComponent = options.AppComponent;
|
|
24
26
|
this._pluginManager = (0, lifecycle_1.getManager)();
|
|
25
27
|
(0, lifecycle_2.initPlugins)(this._pluginManager, options.plugins || []);
|
|
@@ -37,7 +39,19 @@ class Application {
|
|
|
37
39
|
return this._appComponent;
|
|
38
40
|
}
|
|
39
41
|
get error() {
|
|
40
|
-
return this._error;
|
|
42
|
+
return this._error.errorObject;
|
|
43
|
+
}
|
|
44
|
+
setError(err) {
|
|
45
|
+
this._error.set(err);
|
|
46
|
+
}
|
|
47
|
+
clearError() {
|
|
48
|
+
this._error.clear();
|
|
49
|
+
}
|
|
50
|
+
getLoadersData() {
|
|
51
|
+
return this._loader.getAllData;
|
|
52
|
+
}
|
|
53
|
+
setLoadersData(datas) {
|
|
54
|
+
this._loader.setDatas(datas);
|
|
41
55
|
}
|
|
42
56
|
init() {
|
|
43
57
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -47,8 +61,8 @@ class Application {
|
|
|
47
61
|
this._router.init();
|
|
48
62
|
});
|
|
49
63
|
}
|
|
50
|
-
get
|
|
51
|
-
return this.
|
|
64
|
+
get store() {
|
|
65
|
+
return this._store;
|
|
52
66
|
}
|
|
53
67
|
updateComponents({ AppComponent } = {}) {
|
|
54
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -79,12 +93,27 @@ class Application {
|
|
|
79
93
|
});
|
|
80
94
|
}
|
|
81
95
|
getPublicAPI() {
|
|
96
|
+
const self = this;
|
|
82
97
|
return {
|
|
83
|
-
context:
|
|
84
|
-
router:
|
|
85
|
-
appComponent:
|
|
86
|
-
|
|
87
|
-
error
|
|
98
|
+
context: self._context,
|
|
99
|
+
router: self._router,
|
|
100
|
+
appComponent: self._appComponent,
|
|
101
|
+
store: self._store,
|
|
102
|
+
get error() {
|
|
103
|
+
return self.error;
|
|
104
|
+
},
|
|
105
|
+
setError(err) {
|
|
106
|
+
self.setError(err);
|
|
107
|
+
},
|
|
108
|
+
clearError() {
|
|
109
|
+
self.clearError();
|
|
110
|
+
},
|
|
111
|
+
getLoadersData() {
|
|
112
|
+
return self.getLoadersData();
|
|
113
|
+
},
|
|
114
|
+
setLoadersData(datas) {
|
|
115
|
+
self.setLoadersData(datas);
|
|
116
|
+
}
|
|
88
117
|
};
|
|
89
118
|
}
|
|
90
119
|
}
|
|
@@ -24,18 +24,16 @@ export interface IErrorState {
|
|
|
24
24
|
export declare type IAppState = {
|
|
25
25
|
error?: IErrorState;
|
|
26
26
|
};
|
|
27
|
-
export interface IErrorManager {
|
|
28
|
-
getError: IError | undefined;
|
|
29
|
-
error: (err: IError) => void;
|
|
30
|
-
clear: () => void;
|
|
31
|
-
hasError: boolean;
|
|
32
|
-
}
|
|
33
27
|
export interface IApplication {
|
|
34
28
|
readonly context: IAppContext;
|
|
35
29
|
readonly router: IRouter<IPageRouteRecord>;
|
|
36
30
|
readonly appComponent: any;
|
|
37
|
-
readonly
|
|
38
|
-
readonly
|
|
31
|
+
readonly store: IStoreManager;
|
|
32
|
+
readonly error: IError | undefined;
|
|
33
|
+
setError(err: IError): void;
|
|
34
|
+
clearError(): void;
|
|
35
|
+
getLoadersData(): Record<string, any>;
|
|
36
|
+
setLoadersData(datas: Record<string, any>): void;
|
|
39
37
|
}
|
|
40
38
|
export interface IApplicationOptions {
|
|
41
39
|
router: IRouter;
|
|
@@ -5,13 +5,10 @@ export declare type IData = {
|
|
|
5
5
|
export declare type IAppData<Data = {}, appState = any> = {
|
|
6
6
|
ssr: boolean;
|
|
7
7
|
runtimeConfig?: Record<string, string>;
|
|
8
|
+
appState?: appState;
|
|
8
9
|
pageData?: {
|
|
9
10
|
[key: string]: any;
|
|
10
11
|
};
|
|
11
|
-
loadersData?: {
|
|
12
|
-
[x: string]: any;
|
|
13
|
-
};
|
|
14
|
-
appState?: appState;
|
|
15
12
|
filesByRoutId: Record<string, string[]>;
|
|
16
13
|
publicPath: string;
|
|
17
14
|
} & {
|
package/lib/shared/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from './router';
|
|
|
4
4
|
export * from './response';
|
|
5
5
|
export * from './loader';
|
|
6
6
|
export { errorModel } from './models/error';
|
|
7
|
+
export { loaderModel } from './models/loader';
|
|
7
8
|
export * from './applicationTypes';
|
|
8
9
|
export type { Application } from './application';
|
|
9
10
|
export type { IRuntimeConfig } from './runtimeConfigTypes';
|
package/lib/shared/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.createRuntimePlugin = exports.errorModel = void 0;
|
|
17
|
+
exports.createRuntimePlugin = exports.loaderModel = exports.errorModel = void 0;
|
|
18
18
|
__exportStar(require("./helper"), exports);
|
|
19
19
|
__exportStar(require("./routerTypes"), exports);
|
|
20
20
|
__exportStar(require("./router"), exports);
|
|
@@ -22,6 +22,8 @@ __exportStar(require("./response"), exports);
|
|
|
22
22
|
__exportStar(require("./loader"), exports);
|
|
23
23
|
var error_1 = require("./models/error");
|
|
24
24
|
Object.defineProperty(exports, "errorModel", { enumerable: true, get: function () { return error_1.errorModel; } });
|
|
25
|
+
var loader_1 = require("./models/loader");
|
|
26
|
+
Object.defineProperty(exports, "loaderModel", { enumerable: true, get: function () { return loader_1.loaderModel; } });
|
|
25
27
|
__exportStar(require("./applicationTypes"), exports);
|
|
26
28
|
var lifecycle_1 = require("./lifecycle");
|
|
27
29
|
// fix createRuntimePlugin is not portable end
|
|
@@ -15,5 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./loader"), exports);
|
|
18
|
-
__exportStar(require("./loaderManager"), exports);
|
|
19
18
|
__exportStar(require("./types"), exports);
|
|
@@ -4,10 +4,10 @@ export declare const errorModel: import("@shuvi/redox").Model<"error", IErrorSta
|
|
|
4
4
|
error: IError | undefined;
|
|
5
5
|
};
|
|
6
6
|
}, {
|
|
7
|
-
|
|
7
|
+
set(payload?: IError): void;
|
|
8
8
|
clear(): void;
|
|
9
9
|
}, {
|
|
10
|
-
|
|
10
|
+
errorObject(): IError | undefined;
|
|
11
11
|
hasError(): boolean;
|
|
12
12
|
}>;
|
|
13
13
|
export declare type ErrorModel = typeof errorModel;
|
|
@@ -15,7 +15,7 @@ exports.errorModel = (0, redox_1.defineModel)({
|
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
actions: {
|
|
18
|
-
|
|
18
|
+
set(payload) {
|
|
19
19
|
this.setError(payload || constants_1.SHUVI_ERROR.APP_ERROR);
|
|
20
20
|
},
|
|
21
21
|
clear() {
|
|
@@ -25,7 +25,7 @@ exports.errorModel = (0, redox_1.defineModel)({
|
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
27
|
views: {
|
|
28
|
-
|
|
28
|
+
errorObject() {
|
|
29
29
|
return this.error;
|
|
30
30
|
},
|
|
31
31
|
hasError() {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface LoaderState {
|
|
2
|
+
dataByRouteId: Record<string, any>;
|
|
3
|
+
}
|
|
4
|
+
export declare const loaderModel: import("@shuvi/redox").Model<"loader", LoaderState, {}, {
|
|
5
|
+
setDatas(state: LoaderState, newData: Record<string, any>): {
|
|
6
|
+
dataByRouteId: {
|
|
7
|
+
[x: string]: any;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
}, import("@shuvi/redox").RedoxActions, {
|
|
11
|
+
getAllData(): Record<string, any>;
|
|
12
|
+
}>;
|
|
13
|
+
export declare type LoaderModel = typeof loaderModel;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loaderModel = void 0;
|
|
4
|
+
const redox_1 = require("@shuvi/redox");
|
|
5
|
+
const initState = {
|
|
6
|
+
dataByRouteId: {}
|
|
7
|
+
};
|
|
8
|
+
exports.loaderModel = (0, redox_1.defineModel)({
|
|
9
|
+
name: 'loader',
|
|
10
|
+
state: initState,
|
|
11
|
+
reducers: {
|
|
12
|
+
setDatas(state, newData) {
|
|
13
|
+
return Object.assign(Object.assign({}, state), { dataByRouteId: Object.assign(Object.assign({}, state.dataByRouteId), newData) });
|
|
14
|
+
}
|
|
15
|
+
// clearDatas(state) {
|
|
16
|
+
// return {
|
|
17
|
+
// ...state,
|
|
18
|
+
// dataByRouteId: {}
|
|
19
|
+
// };
|
|
20
|
+
// }
|
|
21
|
+
},
|
|
22
|
+
views: {
|
|
23
|
+
getAllData() {
|
|
24
|
+
return this.dataByRouteId;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shuvi/platform-shared",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.5",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/shuvijs/shuvi.git",
|
|
@@ -82,18 +82,18 @@
|
|
|
82
82
|
"node": ">= 12.0.0"
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
|
-
"@shuvi/hook": "1.0.0-rc.
|
|
85
|
+
"@shuvi/hook": "1.0.0-rc.5",
|
|
86
86
|
"@shuvi/redox": "0.0.3",
|
|
87
|
-
"@shuvi/router": "1.0.0-rc.
|
|
88
|
-
"@shuvi/runtime": "1.0.0-rc.
|
|
89
|
-
"@shuvi/service": "1.0.0-rc.
|
|
90
|
-
"@shuvi/shared": "1.0.0-rc.
|
|
91
|
-
"@shuvi/toolpack": "1.0.0-rc.
|
|
92
|
-
"@shuvi/utils": "1.0.0-rc.
|
|
87
|
+
"@shuvi/router": "1.0.0-rc.5",
|
|
88
|
+
"@shuvi/runtime": "1.0.0-rc.5",
|
|
89
|
+
"@shuvi/service": "1.0.0-rc.5",
|
|
90
|
+
"@shuvi/shared": "1.0.0-rc.5",
|
|
91
|
+
"@shuvi/toolpack": "1.0.0-rc.5",
|
|
92
|
+
"@shuvi/utils": "1.0.0-rc.5",
|
|
93
93
|
"redux": "4.1.2"
|
|
94
94
|
},
|
|
95
95
|
"peerDependencies": {
|
|
96
|
-
"@shuvi/service": "1.0.0-rc.
|
|
96
|
+
"@shuvi/service": "1.0.0-rc.5"
|
|
97
97
|
},
|
|
98
98
|
"devDependencies": {
|
|
99
99
|
"@types/minimatch": "3.0.5"
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
declare function createLoaderManager(): {
|
|
2
|
-
getAllData(): Record<string, any>;
|
|
3
|
-
getData(id: string): any;
|
|
4
|
-
setDatas(obj: Record<string, any>): void;
|
|
5
|
-
subscribe(cb: Function): () => void;
|
|
6
|
-
clearAllData(): void;
|
|
7
|
-
};
|
|
8
|
-
export declare const getLoaderManager: () => {
|
|
9
|
-
getAllData(): Record<string, any>;
|
|
10
|
-
getData(id: string): any;
|
|
11
|
-
setDatas(obj: Record<string, any>): void;
|
|
12
|
-
subscribe(cb: Function): () => void;
|
|
13
|
-
clearAllData(): void;
|
|
14
|
-
};
|
|
15
|
-
export declare type LoaderManager = ReturnType<typeof createLoaderManager>;
|
|
16
|
-
export {};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
let loaderManager;
|
|
2
|
-
function createLoaderManager() {
|
|
3
|
-
const datas = new Map();
|
|
4
|
-
const subscribers = [];
|
|
5
|
-
return {
|
|
6
|
-
getAllData() {
|
|
7
|
-
let res = {};
|
|
8
|
-
for (const [id, data] of datas.entries()) {
|
|
9
|
-
res[id] = data;
|
|
10
|
-
}
|
|
11
|
-
return res;
|
|
12
|
-
},
|
|
13
|
-
getData(id) {
|
|
14
|
-
if (!datas.has(id)) {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
return datas.get(id);
|
|
18
|
-
},
|
|
19
|
-
setDatas(obj) {
|
|
20
|
-
for (const [id, data] of Object.entries(obj)) {
|
|
21
|
-
datas.set(id, data);
|
|
22
|
-
}
|
|
23
|
-
subscribers.forEach(fn => fn());
|
|
24
|
-
},
|
|
25
|
-
// setData(id: string, data: any) {
|
|
26
|
-
// datas.set(id, data);
|
|
27
|
-
// subscribers.forEach(fn => fn());
|
|
28
|
-
// },
|
|
29
|
-
subscribe(cb) {
|
|
30
|
-
subscribers.push(cb);
|
|
31
|
-
return () => {
|
|
32
|
-
const index = subscribers.indexOf(cb);
|
|
33
|
-
if (index >= 0) {
|
|
34
|
-
subscribers.splice(index, 1);
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
},
|
|
38
|
-
clearAllData() {
|
|
39
|
-
datas.clear();
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
export const getLoaderManager = () => {
|
|
44
|
-
if (loaderManager) {
|
|
45
|
-
return loaderManager;
|
|
46
|
-
}
|
|
47
|
-
loaderManager = createLoaderManager();
|
|
48
|
-
return loaderManager;
|
|
49
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
declare function createLoaderManager(): {
|
|
2
|
-
getAllData(): Record<string, any>;
|
|
3
|
-
getData(id: string): any;
|
|
4
|
-
setDatas(obj: Record<string, any>): void;
|
|
5
|
-
subscribe(cb: Function): () => void;
|
|
6
|
-
clearAllData(): void;
|
|
7
|
-
};
|
|
8
|
-
export declare const getLoaderManager: () => {
|
|
9
|
-
getAllData(): Record<string, any>;
|
|
10
|
-
getData(id: string): any;
|
|
11
|
-
setDatas(obj: Record<string, any>): void;
|
|
12
|
-
subscribe(cb: Function): () => void;
|
|
13
|
-
clearAllData(): void;
|
|
14
|
-
};
|
|
15
|
-
export declare type LoaderManager = ReturnType<typeof createLoaderManager>;
|
|
16
|
-
export {};
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getLoaderManager = void 0;
|
|
4
|
-
let loaderManager;
|
|
5
|
-
function createLoaderManager() {
|
|
6
|
-
const datas = new Map();
|
|
7
|
-
const subscribers = [];
|
|
8
|
-
return {
|
|
9
|
-
getAllData() {
|
|
10
|
-
let res = {};
|
|
11
|
-
for (const [id, data] of datas.entries()) {
|
|
12
|
-
res[id] = data;
|
|
13
|
-
}
|
|
14
|
-
return res;
|
|
15
|
-
},
|
|
16
|
-
getData(id) {
|
|
17
|
-
if (!datas.has(id)) {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
return datas.get(id);
|
|
21
|
-
},
|
|
22
|
-
setDatas(obj) {
|
|
23
|
-
for (const [id, data] of Object.entries(obj)) {
|
|
24
|
-
datas.set(id, data);
|
|
25
|
-
}
|
|
26
|
-
subscribers.forEach(fn => fn());
|
|
27
|
-
},
|
|
28
|
-
// setData(id: string, data: any) {
|
|
29
|
-
// datas.set(id, data);
|
|
30
|
-
// subscribers.forEach(fn => fn());
|
|
31
|
-
// },
|
|
32
|
-
subscribe(cb) {
|
|
33
|
-
subscribers.push(cb);
|
|
34
|
-
return () => {
|
|
35
|
-
const index = subscribers.indexOf(cb);
|
|
36
|
-
if (index >= 0) {
|
|
37
|
-
subscribers.splice(index, 1);
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
},
|
|
41
|
-
clearAllData() {
|
|
42
|
-
datas.clear();
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
const getLoaderManager = () => {
|
|
47
|
-
if (loaderManager) {
|
|
48
|
-
return loaderManager;
|
|
49
|
-
}
|
|
50
|
-
loaderManager = createLoaderManager();
|
|
51
|
-
return loaderManager;
|
|
52
|
-
};
|
|
53
|
-
exports.getLoaderManager = getLoaderManager;
|