Files
yudao-ui-admin-vben/packages/preference/src/setup.ts
2024-05-24 23:11:03 +08:00

31 lines
862 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { DeepPartial, Preference } from '@vben-core/typings';
import { PreferenceCache } from './cache';
import { overridesPreference } from './preference';
interface SetupPreferenceOptions {
/**
* @zh_CN 环境
*/
env: string;
/**
* @zh_CN 应用名,由于 @vben/preference 是公用的后续可能有多个app为了防止多个app缓存冲突可在这里配置应用名
* 应用名将被用于持久化的前缀
*/
namespace: string;
/**
* @zh_CN app自行覆盖偏好设置
*/
overrides?: DeepPartial<Preference>;
}
async function setupPreference(options: SetupPreferenceOptions) {
const { env, namespace, overrides = {} } = options;
const cache = new PreferenceCache(`${namespace}-${env}`);
overridesPreference(overrides, cache);
}
export { setupPreference };
export type { SetupPreferenceOptions };