diff --git a/ivette/src/dome/src/renderer/data/settings.ts b/ivette/src/dome/src/renderer/data/settings.ts index 19e6730a15745bdce3be6a3b2e6547be7cf693f3..e6e3a8a246e453da738b9ec83e2798b058924b97 100644 --- a/ivette/src/dome/src/renderer/data/settings.ts +++ b/ivette/src/dome/src/renderer/data/settings.ts @@ -29,6 +29,14 @@ interface Settings<A> { /** Global settings. + This utility class allows you to share accross several + components and windows the parameters associated to global settings. + + However, it is important to note that global settings are uniquely identified + by their `name`. If you have multiple definitions of global settings class + with the same name, they will actually share the same value. Hence, if they + have different default values or decoders, this might leads to strange + results. */ export class GlobalSettings<A> { name: string; diff --git a/ivette/src/dome/src/renderer/dome.ts b/ivette/src/dome/src/renderer/dome.ts index 873367b4b83e9842581442305af84f8d4e72b4d9..ab451cbafcb378f968e2188e9794c8f5d9e51c1f 100644 --- a/ivette/src/dome/src/renderer/dome.ts +++ b/ivette/src/dome/src/renderer/dome.ts @@ -636,6 +636,25 @@ export function useStringOptSettings(key: string | undefined) { ); } +/** Direct shortcut to [[dome/data/settings.useWindowSettings]]. */ +export const useWindowSettings = Settings.useWindowSettings; + +/** + Utility shortcut to [[dome/data/settings.useGlobalSettings]] + with global settings class created on-the-fly. + */ +export function useGlobalSettings<A extends Json.json>( + globalKey: string, + decoder: Json.Loose<A>, + defaultValue: A +) { + // Object creation is cheaper than useMemo... + const G = new Settings.GlobalSettings( + globalKey, decoder, Json.identity, defaultValue + ); + return Settings.useGlobalSettings(G); +} + // -------------------------------------------------------------------------- // --- Pretty Printing (Browser Console) // --------------------------------------------------------------------------