lodash#once TypeScript Examples
The following examples show how to use
lodash#once.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TaskScheduler.ts From backstage with Apache License 2.0 | 6 votes |
/**
* Instantiates a task manager instance for the given plugin.
*
* @param pluginId - The unique ID of the plugin, for example "catalog"
* @returns A {@link PluginTaskScheduler} instance
*/
forPlugin(pluginId: string): PluginTaskScheduler {
const databaseFactory = once(async () => {
const knex = await this.databaseManager.forPlugin(pluginId).getClient();
await migrateBackendTasks(knex);
const janitor = new PluginTaskSchedulerJanitor({
knex,
waitBetweenRuns: Duration.fromObject({ minutes: 1 }),
logger: this.logger,
});
janitor.start();
return knex;
});
return new PluginTaskSchedulerImpl(
databaseFactory,
this.logger.child({ plugin: pluginId }),
);
}
Example #2
Source File: SwidgetLoader.tsx From mo360-ftk with MIT License | 6 votes |
public prerenderSetup = once(() => {
const { name, url } = this.props;
return this.componentLoader
.load({ name, url })
.then((swidget) => {
this.setState({ swidget });
})
.catch((err: Error) => {
this.handleError(err);
});
});
Example #3
Source File: Provider.tsx From mo360-ftk with MIT License | 6 votes |
private bindServices = once((container: IDiContainer) => {
container.bind<ConfigService>(ConfigService).toDynamicValue((context: IDiContext) => {
let config: IConfigData = defaultConfig;
try {
const boundContainer = findBoundContainer(context.container, ConfigService);
// prevent a recursion loop if the configuration is bound in our own container
if (boundContainer.id !== context.container.id) {
config = boundContainer.get(ConfigService).getConfig();
}
} catch {
// swallow the error; it means we have no config already bound and fallback to use the defaultConfig
}
const overwrittenConfig = this.props.config || {};
const merged = merge({ ...config }, overwrittenConfig);
return new ConfigService(merged);
});
});
Example #4
Source File: App.tsx From mo360-ftk with MIT License | 6 votes |
private setup = once((containerFromContext: IDiContainer | null) => {
const isHotLoaded = containerFromContext !== null;
const defaultContainer = new Container();
const appContainer = defaultContainer.createChild();
if (!isHotLoaded) {
registerDefaultDependencies(defaultContainer, this.props.name);
} else {
defaultContainer.parent = containerFromContext;
registerSwidgetDependencies(defaultContainer, this.props.name);
}
this.useChildrenAsDefaultRouteIfNotSet(defaultContainer);
if (this.props.init) {
const custom = this.props.init(appContainer);
// LEGACY: we need this as the container passed to kernel() in the init func
// returns a custom container - this should not be done in new apps and is deprecated
if (custom && custom !== appContainer) {
return custom;
}
}
return appContainer;
});
Example #5
Source File: I18nProvider.tsx From mo360-ftk with MIT License | 6 votes |
private bindService = once((container: IDiContainer) => {
container.bind(I18nService).toDynamicValue((context: IDiContext) => {
const getLang = () => this.props.lang;
const setLang = this.props.setLang;
const translationMap = context.container.get<ITranslationMap>(serviceIds.translations);
const registry = createTranslationRegistry(translationMap);
return new I18nService(registry, getLang, setLang, this.props.intl);
});
});
Example #6
Source File: ComponentLoaderTest.tsx From mo360-ftk with MIT License | 6 votes |
public prerenderSetup = once(() => {
const firstLoadStart = new Date().getTime();
this.loadExternalComponent().then((swidget) => {
const firstLoadTime = new Date().getTime() - firstLoadStart;
this.setState({ swidget, firstLoadTime });
const secondLoadStart = new Date().getTime();
// test if the second request is answered by cache - should be very fast to load
this.loadExternalComponent().then(() => {
const secondLoadTime = new Date().getTime() - secondLoadStart;
this.setState({ secondLoadTime });
});
});
});
Example #7
Source File: ComponentLoaderWithChildrenTest.tsx From mo360-ftk with MIT License | 6 votes |
public setup = once(() => {
this.componentLoader
.load({
name: 'ExternalComponentWithChildren',
url: 'http://swidgets.localtest.me:8081/ExternalComponentWithChildren.js',
})
.then((swidget) => {
this.setState({ swidget });
});
});
Example #8
Source File: containercontext.tsx From mo360-ftk with MIT License | 6 votes |
private test = once(() => {
this.container1.bind<string>('container1').toConstantValue('container1');
this.container1.bind<string>('container3').toConstantValue('container1');
this.container3.bind<string>('container3').toConstantValue('container3');
const ret = (
<>
<h1 className="alldifferent">{this.allContainersAreDifferent().toString()}</h1>
<h1 className="parentaccess">{this.dependenciesAreResolvedFromParents().toString()}</h1>
<h1 className="overwriteparent">{this.childContainersOverwriteParentDependencies().toString()}</h1>
</>
);
return ret;
});
Example #9
Source File: BindToDi.tsx From mo360-ftk with MIT License | 5 votes |
private registerServices = once((container: IDiContainer) => {
this.props.services(container);
});
Example #10
Source File: ChildContainer.tsx From mo360-ftk with MIT License | 5 votes |
private setupContainer = once((container: IDiContainer) => {
const childContainer = new Container();
childContainer.parent = container;
return childContainer;
});
Example #11
Source File: Provider.tsx From mo360-ftk with MIT License | 5 votes |
private bindServices = once((container: IDiContainer) => {
container.bind<ErrorHandler>(ErrorHandler).toConstantValue(
new ErrorHandler({
handleError: this.handleError
})
)
});
Example #12
Source File: TranslationProvider.tsx From mo360-ftk with MIT License | 5 votes |
public setupTranslations = once((container: IDiContainer) => {
const parentTranslations = container.get<ITranslationMap>(serviceIds.translations);
const newTranslations = this.props.translations;
const configTranslations = getConfigTranslationMap(this.configService);
const mergedTranslations = mergeTranslations(parentTranslations, newTranslations, configTranslations);
container.bind<ITranslationMap>(serviceIds.translations).toConstantValue(mergedTranslations);
});
Example #13
Source File: Route.tsx From mo360-ftk with MIT License | 5 votes |
private bindService = once((container: IDiContainer) => {
const routerService = new RouterService(this.router, this.urlFormatStrategy);
container.bind<RouterService>(RouterService).toConstantValue(routerService);
});
Example #14
Source File: Route.tsx From mo360-ftk with MIT License | 5 votes |
private setupRoutes = once(() => {
this.routes.map((route) => {
this.router.addRoute(route.name, route.pattern, route.component, route.forceRemount);
});
});
Example #15
Source File: InterconnectionComponent.tsx From mo360-ftk with MIT License | 5 votes |
public subscribe = once(() => {
this.interconnection.subscribe<string>('foo', (data) => {
this.setState({
events: this.state.events.concat([data]),
});
});
});