scrivito
Version:
Scrivito is a professional, yet easy to use SaaS Enterprise Content Management Service, built for digital agencies and medium to large businesses. It is completely maintenance-free, cost-effective, and has unprecedented performance and security.
28 lines (23 loc) • 802 B
text/typescript
import { onReset } from 'scrivito_sdk/common';
import { notifyExternalDataWrite } from 'scrivito_sdk/data_integration/external_data_query';
import {
LazyAsync,
normalizeLazyAsync,
} from 'scrivito_sdk/data_integration/lazy_async';
let config: {
[dataClassName: string]: () => Promise<false | undefined>;
} = {};
export async function configureExternalDataInvalidation(
dataClassName: string,
refetchOnWindowFocus: LazyAsync<false | undefined>
): Promise<void> {
config[dataClassName] = normalizeLazyAsync(refetchOnWindowFocus);
}
export async function invalidateExternalData(): Promise<void> {
for (const dataClassName of Object.keys(config)) {
if ((await config[dataClassName]()) ?? true) {
notifyExternalDataWrite(dataClassName);
}
}
}
onReset(() => (config = {}));