MCPcopy Index your code
hub / github.com/nukeop/nuclear / createCoreSettingsHost

Function createCoreSettingsHost

packages/player/src/services/settingsHost.ts:75–115  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

73};
74
75export const createCoreSettingsHost = (): SettingsHost => {
76 const coreSource: SettingSource = { type: 'core' };
77 return {
78 register: async (definitions: SettingDefinition[]) => {
79 const registeredIds = useSettingsStore
80 .getState()
81 .register(definitions, coreSource);
82 return { registered: registeredIds };
83 },
84 get: async <T extends SettingValue = SettingValue>(id: string) => {
85 const fullyQualifiedId = normalizeId(coreSource, id);
86 const currentValue = useSettingsStore
87 .getState()
88 .getValue(fullyQualifiedId);
89 return currentValue as T | undefined;
90 },
91 set: async (id: string, value: SettingValue) => {
92 const fullyQualifiedId = normalizeId(coreSource, id);
93 await useSettingsStore.getState().setValue(fullyQualifiedId, value);
94 },
95 getGlobal: getGlobalSetting,
96 setGlobal: setGlobalSetting,
97 subscribe: <T extends SettingValue = SettingValue>(
98 id: string,
99 listener: (value: T | undefined) => void,
100 ) => {
101 const fullyQualifiedId = normalizeId(coreSource, id);
102 let previousValue = useSettingsStore
103 .getState()
104 .getValue(fullyQualifiedId) as T | undefined;
105 const unsubscribe = useSettingsStore.subscribe((state) => {
106 const nextValue = state.getValue(fullyQualifiedId) as T | undefined;
107 if (nextValue !== previousValue) {
108 previousValue = nextValue;
109 listener(nextValue);
110 }
111 });
112 return unsubscribe;
113 },
114 };
115};
116
117export const coreSettingsHost: SettingsHost = createCoreSettingsHost();

Callers 2

settingsHost.tsFile · 0.85

Calls 4

getStateMethod · 0.80
normalizeIdFunction · 0.70
registerMethod · 0.45
subscribeMethod · 0.45

Tested by

no test coverage detected