import React from 'react'; import type { Plugin } from './app-registry'; import { AppRegistry } from './app-registry'; declare class ActivateHelpersImpl { private cleanupFns; private deactivateController; constructor(); /** * A signal for the abort controller that will be aborted when the cleanup * method is called. Helpful to be able to abort or check whether or not * plugin is still active in async tasks triggered during plugin activate * phase */ get signal(): AbortSignal; /** * Helper method to subscribe to events on a generic event emitter. Events * will be added to the cleanup set and will be cleaned up when `cleanup` is * called */ on: (emitter: { on(evt: string, fn: (...args: any) => any): any; removeListener(evt: string, fn: (...args: any) => any): any; }, evt: string, fn: (...args: any) => any) => void; /** * Add an arbitrary callback to the cleanup set */ addCleanup: (fn?: () => void) => void; /** * Call all the cleanup callbacks. This includes any events listeners set up * with an `on` helper and everything that was added with `addCleanup` */ cleanup: () => void; } export type ActivateHelpers = Pick; export declare function createActivateHelpers(): ActivateHelpers; type Registries = { globalAppRegistry: AppRegistry; localAppRegistry: AppRegistry; }; type Services unknown>> = { [SvcName in keyof S]: ReturnType; }; export type HadronPluginConfig unknown>, A extends Plugin> = { name: string; component: React.ComponentType; /** * Plugin activation method, will receive any props passed to the component, * and global and local app registry instances to subscribe to any relevant * events. Should return plugin store and an optional deactivate method to * clean up subscriptions or any other store-related state */ activate: (initialProps: T, services: Registries & Services, helpers: ActivateHelpers) => A; }; type MockOptions = { pluginName: string; mockedEnvironment: boolean; mockServices: Record; disableChildPluginRendering: boolean; }; /** * Helper method to "create" a service locator function for a particular * service. This method guarantees that service locators are used only in * appropriate context. Every service locator function in the application should * be created with this method. */ export declare function createServiceLocator any>(fn: T, name?: string): T; /** * Optional service provider creation method. In some cases service providers * need access to other service locators to facilitate service injections. In * these cases service provider can be wrapped with the createServiceProvider * function to allow usage of serviceLocator functions in providers outside of * the usual hadron plugin "activate" lifecycle. */ export declare function createServiceProvider>(fn: T): T; export type HadronPluginComponent unknown>, A extends Plugin> = React.FunctionComponent & { displayName: string; /** * Hook that will activate plugin in the current rendering scope without * actually rendering it. Useful to set up plugins that are rendered * conditionally and have to subscribe to event listeners earlier than the * first render in their lifecycle * * @example * const Plugin = registerHadronPlugin(...); * * function Component() { * Plugin.useActivate(); * const [pluginVisible] = useState(false); * * // This Plugin component will already have its store set up and listening * // to the events even before rendering * return (pluginVisible && ) * } */ useActivate(props: T): A; /** * Convenience method for testing: allows to override services and app * registries available in the plugin context * * @example * const PluginWithLogger = registerHadronPlugin({ ... }, { logger: loggerLocator }); * * const MockPlugin = PluginWithLogger.withMockServices({ logger: Sinon.stub() }); * * @param mocks Overrides for the services locator values and registries * passed to the plugin in runtime. When `globalAppRegistry` * override is passed, it will be also used for the * localAppRegistry override unless `localAppRegistry` is also * explicitly passed as a mock service. */ withMockServices(mocks: Partial>, options?: Partial>): HadronPluginComponent; }; /** * Creates a hadron plugin that will be automatically activated on first render * and cleaned up when localAppRegistry unmounts * * @param config Hadron plugin configuration * @param services Map of service locator functions that plugin depends on * * @returns Hadron plugin component * * @example * const CreateCollectionPlugin = registerHadronPlugin({ * name: 'CreateCollection', * component: CreateCollectionModal, * activate(opts, { globalAppRegistry }) { * const store = configureStore(...); * const openCreateCollectionModal = (ns) => { * store.dispatch(openModal(ns)); * } * globalAppRegistry.on('create-collection', openCreateCollectionModal); * return { * store, * deactivate() { * globalAppRegistry.removeEventListener( * 'create-collection', * openCreateCollectionModal * ); * } * } * } * }); * * @example * // app.js * import CompassLogging from '@mongodb-js/compass-logging'; * import { LoggingProvider } from '@mongodb-js/compass-logging/provider'; * * ReactDOM.render( * * * * ) * * // plugin.js * import { logging } from '@mongodb-js/compass-logging/provider' * * const PluginWithLogger = registerHadronPlugin({ * name: 'LoggingPlugin', * component: () => null, * activate(opts, { logging }) { * logging.log('Plugin activated!'); * } * }, { logging }) */ export declare function registerHadronPlugin unknown>, A extends Plugin>(config: HadronPluginConfig, services?: S): HadronPluginComponent; export {}; //# sourceMappingURL=register-plugin.d.ts.map