@snap/camera-kit
Version:
Camera Kit Web
32 lines • 1.38 kB
JavaScript
import { combineLatest, take } from "rxjs";
import { Injectable } from "@snap/ts-inject";
import { lensCoreFactory } from "../lens-core-module/loader/lensCoreFactory";
import { getLogger } from "../logger/logger";
import { remoteConfigurationFactory } from "./remoteConfiguration";
import { toLensCoreConfigValue } from "./util";
const logger = getLogger("setPreloadedConfiguration");
const SYNC_REQUIRED_CONFIG_IDS = [];
export const setPreloadedConfiguration = Injectable("setPreloadedConfiguration", [lensCoreFactory.token, remoteConfigurationFactory.token], (lensCore, remoteConfiguration) => {
if (SYNC_REQUIRED_CONFIG_IDS.length === 0) {
return;
}
combineLatest(SYNC_REQUIRED_CONFIG_IDS.map((id) => remoteConfiguration.get(id)))
.pipe(take(1))
.subscribe({
next: (configArrays) => {
const inputs = configArrays
.flat()
.flatMap(({ configId, value }) => {
if (!value)
return [];
const convertedValue = toLensCoreConfigValue(value);
if (!convertedValue)
return [];
return [{ configId, value: convertedValue }];
});
lensCore.setPreloadedConfiguration(inputs);
},
error: logger.error,
});
});
//# sourceMappingURL=preloadConfiguration.js.map