mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-02-28 21:20:28 +00:00
refactor: Container的职责合并到App
This commit is contained in:
parent
d5c8df8729
commit
de65b5f83d
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ali/lowcode-runtime",
|
||||
"version": "1.0.8-0",
|
||||
"version": "1.0.9",
|
||||
"description": "Runtime for Ali lowCode engine",
|
||||
"files": [
|
||||
"es",
|
||||
|
||||
@ -1,92 +0,0 @@
|
||||
import Provider from './provider';
|
||||
|
||||
export interface ILayoutOptions {
|
||||
componentName?: string;
|
||||
props?: any;
|
||||
}
|
||||
|
||||
export interface IErrorBoundaryConfig {
|
||||
fallbackUI: any;
|
||||
afterCatch?: (...rest: any) => any
|
||||
}
|
||||
|
||||
export default class Container {
|
||||
private renderer: any = null;
|
||||
|
||||
private layouts: { [key: string]: { content: any; props: any } } = {};
|
||||
|
||||
private loading: any = null;
|
||||
|
||||
private errorBoundary: IErrorBoundaryConfig = { fallbackUI: () => '', afterCatch: () => {} };
|
||||
|
||||
private providers: { [key: string]: Provider; } = {};
|
||||
|
||||
registerRenderer(renderer: any): any {
|
||||
this.renderer = renderer;
|
||||
}
|
||||
|
||||
registerLayout(Layout: any, options: ILayoutOptions): any {
|
||||
if (!options) {
|
||||
return;
|
||||
}
|
||||
const { componentName, props = {} } = options;
|
||||
if (!componentName || !Layout) {
|
||||
return;
|
||||
}
|
||||
this.layouts[componentName] = { content: Layout, props };
|
||||
}
|
||||
|
||||
registerLoading(component: any) {
|
||||
if (!component) {
|
||||
return;
|
||||
}
|
||||
this.loading = component;
|
||||
}
|
||||
|
||||
registerErrorBoundary(config: IErrorBoundaryConfig) {
|
||||
if (!config) {
|
||||
return;
|
||||
}
|
||||
this.errorBoundary = config;
|
||||
}
|
||||
|
||||
registerProvider(CustomProvider: any) {
|
||||
try {
|
||||
const p = new CustomProvider();
|
||||
this.providers[p.getContainerId()] = p;
|
||||
} catch (error) {
|
||||
console.error(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
getLayout(componentName: string) {
|
||||
if (!componentName) {
|
||||
return;
|
||||
}
|
||||
return this.layouts[componentName];
|
||||
}
|
||||
|
||||
getRenderer(): any {
|
||||
return this.renderer;
|
||||
}
|
||||
|
||||
getLoading(): any {
|
||||
return this.loading;
|
||||
}
|
||||
|
||||
getErrorBoundary(): any {
|
||||
return this.errorBoundary;
|
||||
}
|
||||
|
||||
getProvider(id?: string) {
|
||||
if (!id) {
|
||||
for (const key in this.providers) {
|
||||
if (Object.prototype.hasOwnProperty.call(this.providers, key)) {
|
||||
return this.providers[key];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return this.providers[id];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,56 +1,98 @@
|
||||
import Container, { ILayoutOptions, IErrorBoundaryConfig } from './container';
|
||||
import Provider from './provider';
|
||||
import runApp from './runApp';
|
||||
|
||||
class App {
|
||||
private container: Container;
|
||||
export interface ILayoutOptions {
|
||||
componentName?: string;
|
||||
props?: any;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
this.container = new Container();
|
||||
}
|
||||
export interface IErrorBoundaryConfig {
|
||||
fallbackUI: any;
|
||||
afterCatch?: (...rest: any) => any
|
||||
}
|
||||
|
||||
class App {
|
||||
private renderer: any = null;
|
||||
|
||||
private layouts: { [key: string]: { content: any; props: any } } = {};
|
||||
|
||||
private loading: any = null;
|
||||
|
||||
private errorBoundary: IErrorBoundaryConfig = { fallbackUI: () => '', afterCatch: () => {} };
|
||||
|
||||
private providers: { [key: string]: Provider; } = {};
|
||||
|
||||
run() {
|
||||
runApp();
|
||||
}
|
||||
|
||||
registerRenderer(renderer: any): any {
|
||||
this.container.registerRenderer(renderer);
|
||||
this.renderer = renderer;
|
||||
}
|
||||
|
||||
registerLayout(Layout: any, options: ILayoutOptions): any {
|
||||
this.container.registerLayout(Layout, options);
|
||||
if (!options) {
|
||||
return;
|
||||
}
|
||||
const { componentName, props = {} } = options;
|
||||
if (!componentName || !Layout) {
|
||||
return;
|
||||
}
|
||||
this.layouts[componentName] = { content: Layout, props };
|
||||
}
|
||||
|
||||
registerLoading(component: any) {
|
||||
this.container.registerLoading(component);
|
||||
}
|
||||
|
||||
registerProvider(CustomProvider: any) {
|
||||
this.container.registerProvider(CustomProvider);
|
||||
if (!component) {
|
||||
return;
|
||||
}
|
||||
this.loading = component;
|
||||
}
|
||||
|
||||
registerErrorBoundary(config: IErrorBoundaryConfig) {
|
||||
this.container.registerErrorBoundary(config);
|
||||
if (!config) {
|
||||
return;
|
||||
}
|
||||
this.errorBoundary = config;
|
||||
}
|
||||
|
||||
registerProvider(CustomProvider: any) {
|
||||
try {
|
||||
const p = new CustomProvider();
|
||||
this.providers[p.getContainerId()] = p;
|
||||
} catch (error) {
|
||||
console.error(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
getLayout(componentName: string) {
|
||||
return this.container.getLayout(componentName);
|
||||
if (!componentName) {
|
||||
return;
|
||||
}
|
||||
return this.layouts[componentName];
|
||||
}
|
||||
|
||||
getRenderer(): any {
|
||||
return this.container.getRenderer();
|
||||
return this.renderer;
|
||||
}
|
||||
|
||||
getLoading(): any {
|
||||
return this.container.getLoading();
|
||||
return this.loading;
|
||||
}
|
||||
|
||||
getErrorBoundary(): IErrorBoundaryConfig {
|
||||
return this.container.getErrorBoundary();
|
||||
getErrorBoundary(): any {
|
||||
return this.errorBoundary;
|
||||
}
|
||||
|
||||
getProvider(id?: string): Provider | undefined {
|
||||
return this.container.getProvider(id);
|
||||
getProvider(id?: string) {
|
||||
if (!id) {
|
||||
for (const key in this.providers) {
|
||||
if (Object.prototype.hasOwnProperty.call(this.providers, key)) {
|
||||
return this.providers[key];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return this.providers[id];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user