parent
							
								
									bce02ad1d7
								
							
						
					
					
						commit
						9249dcb896
					
				@ -8,6 +8,7 @@ export const app = new Application({
 | 
			
		||||
  },
 | 
			
		||||
  plugins: [NocoBaseClientPresetPlugin],
 | 
			
		||||
  ws: true,
 | 
			
		||||
  loadRemotePlugins: true,
 | 
			
		||||
  devDynamicImport,
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -38,6 +38,7 @@ export interface ApplicationOptions {
 | 
			
		||||
  scopes?: Record<string, any>;
 | 
			
		||||
  router?: RouterOptions;
 | 
			
		||||
  devDynamicImport?: DevDynamicImport;
 | 
			
		||||
  loadRemotePlugins?: boolean;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export class Application {
 | 
			
		||||
@ -75,7 +76,7 @@ export class Application {
 | 
			
		||||
      ...options.router,
 | 
			
		||||
      renderComponent: this.renderComponent.bind(this),
 | 
			
		||||
    });
 | 
			
		||||
    this.pm = new PluginManager(options.plugins, this);
 | 
			
		||||
    this.pm = new PluginManager(options.plugins, options.loadRemotePlugins, this);
 | 
			
		||||
    this.addDefaultProviders();
 | 
			
		||||
    this.addReactRouterComponents();
 | 
			
		||||
    this.addProviders(options.providers || []);
 | 
			
		||||
 | 
			
		||||
@ -19,6 +19,7 @@ export class PluginManager {
 | 
			
		||||
 | 
			
		||||
  constructor(
 | 
			
		||||
    protected _plugins: PluginType[],
 | 
			
		||||
    protected loadRemotePlugins: boolean,
 | 
			
		||||
    protected app: Application,
 | 
			
		||||
  ) {
 | 
			
		||||
    this.app = app;
 | 
			
		||||
@ -27,7 +28,9 @@ export class PluginManager {
 | 
			
		||||
 | 
			
		||||
  async init(_plugins: PluginType[]) {
 | 
			
		||||
    await this.initStaticPlugins(_plugins);
 | 
			
		||||
    await this.initRemotePlugins();
 | 
			
		||||
    if (this.loadRemotePlugins) {
 | 
			
		||||
      await this.initRemotePlugins();
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private async initStaticPlugins(_plugins: PluginType[] = []) {
 | 
			
		||||
 | 
			
		||||
@ -331,8 +331,8 @@ describe('Application', () => {
 | 
			
		||||
        router,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      const ErrorFallback = () => {
 | 
			
		||||
        return <div>ErrorFallback</div>;
 | 
			
		||||
      const AppError = () => {
 | 
			
		||||
        return <div>AppError</div>;
 | 
			
		||||
      };
 | 
			
		||||
      const Foo = () => {
 | 
			
		||||
        throw new Error('error');
 | 
			
		||||
@ -340,7 +340,7 @@ describe('Application', () => {
 | 
			
		||||
      };
 | 
			
		||||
      app.use(Foo);
 | 
			
		||||
      app.addComponents({
 | 
			
		||||
        ErrorFallback,
 | 
			
		||||
        AppError,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      const originalConsoleWarn = console.error;
 | 
			
		||||
@ -352,8 +352,7 @@ describe('Application', () => {
 | 
			
		||||
      await sleep(10);
 | 
			
		||||
      expect(fn).toBeCalled();
 | 
			
		||||
 | 
			
		||||
      expect(screen.getByText('ErrorFallback')).toBeInTheDocument();
 | 
			
		||||
      screen.debug();
 | 
			
		||||
      expect(screen.getByText('AppError')).toBeInTheDocument();
 | 
			
		||||
 | 
			
		||||
      console.error = originalConsoleWarn;
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
@ -23,7 +23,7 @@ export const AppComponent: FC<AppComponentProps> = observer((props) => {
 | 
			
		||||
  if (app.error?.code === 'LOAD_ERROR') return app.renderComponent('AppError', { app });
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
    <ErrorBoundary FallbackComponent={app.getComponent<FallbackProps>('ErrorFallback')} onError={handleErrors}>
 | 
			
		||||
    <ErrorBoundary FallbackComponent={app.getComponent<FallbackProps>('AppError')} onError={handleErrors}>
 | 
			
		||||
      <ApplicationContext.Provider value={app}>
 | 
			
		||||
        {app.maintained && app.maintaining && app.renderComponent('AppMaintainingDialog', { app })}
 | 
			
		||||
        {app.renderComponent('AppMain')}
 | 
			
		||||
 | 
			
		||||
@ -28,7 +28,7 @@ export const compose = (...components: [ComponentType, any][]) => {
 | 
			
		||||
        <Child {...childProps}>{children}</Child>
 | 
			
		||||
      </Parent>
 | 
			
		||||
    );
 | 
			
		||||
    ComposeComponent.displayName = Child.displayName;
 | 
			
		||||
    ComposeComponent.displayName = Child.displayName || Child.name;
 | 
			
		||||
    return ComposeComponent;
 | 
			
		||||
  }, BlankComponent);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -74,3 +74,4 @@ export const SchemaComponentProvider: React.FC<ISchemaComponentProvider> = (prop
 | 
			
		||||
    </SchemaComponentContext.Provider>
 | 
			
		||||
  );
 | 
			
		||||
};
 | 
			
		||||
SchemaComponentProvider.displayName = 'SchemaComponentProvider';
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user