Skip to main content

Recipes

Register a default feature implementation

Use initUpdatableFeature<T>() once per feature name; later calls from other modules can override the default with their own implementation of the same interface.

import { hasFeature, initUpdatableFeature } from '@quik/core';
import type { IQCache } from '@quik/core';

if (!hasFeature('IQCache')) {
initUpdatableFeature<IQCache>('IQCache', new MyCacheProvider());
}

Load feature flags from config

import { getConfig, FeatureFlagStore } from '@quik/core';

FeatureFlagStore.loadFromConfig(getConfig().object('featureFlags', {}));

if (FeatureFlagStore.has('new-ui')) {
// ...
}

Instrument a service with telemetry spans

QObject subclasses (services, entities, and most framework objects) can start/end telemetry spans without depending on a specific telemetry provider — startSpan() returns undefined when no provider is active.

import { QObject } from '@quik/core';

class ReportGenerator extends QObject {
public async generate() {
const span = this.startSpan('report.generate');
try {
// ... work ...
} catch (err) {
this.recordSpanError(span, err);
throw err;
} finally {
this.endSpan(span);
}
}
}

Require configuration keys at startup

import { requireConfig } from '@quik/core';

requireConfig('crypto.appKey', 'app.name');

requireConfig throws a plain Error (not a QTranslatableError) listing any keys that resolve to an empty string.