Merge branch 'refactor/remove-container' into 'release/1.0.0'

将Container的职责合并到App



See merge request !1000128
This commit is contained in:
荣彬 2020-09-28 16:55:17 +08:00
commit 0428b5c302
5 changed files with 68 additions and 118 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@ali/lowcode-react-provider",
"version": "1.0.8-0",
"version": "1.0.9",
"description": "React Provider for Runtime",
"files": [
"es",

View File

@ -1,4 +1,4 @@
import { createElement, ReactType, ReactElement } from 'react';
import { createElement, ComponentType, ReactElement } from 'react';
import ReactDOM from 'react-dom';
import { Router } from '@recore/router';
import { app, Provider } from '@ali/lowcode-runtime';
@ -46,7 +46,7 @@ export default class ReactProvider extends Provider {
}
// 内置实现 for 动态化渲染
getRouterView(): ReactType {
getRouterView(): ComponentType {
const routerConfig = this.getRouterConfig();
if (!routerConfig) {
return () => null;
@ -84,7 +84,7 @@ export default class ReactProvider extends Provider {
defined: { keepAlive: true },
});
}
const appHelper = new AppHelper();
const appHelper = new AppHelper({});
appHelper.set('utils', this.getUtils());
appHelper.set('constants', this.getConstants());
const self = this;

View File

@ -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",

View File

@ -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];
}
}
}

View File

@ -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];
}
}
}