(opts: {
forceNew: boolean|null,
syncedStorage: SettingsStorage|null,
globalStorage: SettingsStorage|null,
localStorage: SettingsStorage|null,
settingRegistrations: SettingRegistration[]|null,
console: Console|null,
logSettingAccess?: (name: string, value: number|string|boolean) => Promise<void>,
runSettingsMigration?: boolean,
} = {
forceNew: null,
syncedStorage: null,
globalStorage: null,
localStorage: null,
settingRegistrations: null,
console: null
})
| 97 | } |
| 98 | |
| 99 | static instance(opts: { |
| 100 | forceNew: boolean|null, |
| 101 | syncedStorage: SettingsStorage|null, |
| 102 | globalStorage: SettingsStorage|null, |
| 103 | localStorage: SettingsStorage|null, |
| 104 | settingRegistrations: SettingRegistration[]|null, |
| 105 | console: Console|null, |
| 106 | logSettingAccess?: (name: string, value: number|string|boolean) => Promise<void>, |
| 107 | runSettingsMigration?: boolean, |
| 108 | } = { |
| 109 | forceNew: null, |
| 110 | syncedStorage: null, |
| 111 | globalStorage: null, |
| 112 | localStorage: null, |
| 113 | settingRegistrations: null, |
| 114 | console: null |
| 115 | }): Settings { |
| 116 | const { |
| 117 | forceNew, |
| 118 | syncedStorage, |
| 119 | globalStorage, |
| 120 | localStorage, |
| 121 | settingRegistrations, |
| 122 | logSettingAccess, |
| 123 | runSettingsMigration, |
| 124 | console, |
| 125 | } = opts; |
| 126 | if (!Root.DevToolsContext.globalInstance().has(Settings) || forceNew) { |
| 127 | if (!syncedStorage || !globalStorage || !localStorage || !settingRegistrations || !console) { |
| 128 | throw new Error(`Unable to create settings: global and local storage must be provided: ${new Error().stack}`); |
| 129 | } |
| 130 | |
| 131 | Root.DevToolsContext.globalInstance().set(Settings, new Settings({ |
| 132 | syncedStorage, |
| 133 | globalStorage, |
| 134 | localStorage, |
| 135 | settingRegistrations, |
| 136 | logSettingAccess, |
| 137 | runSettingsMigration, |
| 138 | console, |
| 139 | })); |
| 140 | } |
| 141 | |
| 142 | return Root.DevToolsContext.globalInstance().get(Settings); |
| 143 | } |
| 144 | |
| 145 | static removeInstance(): void { |
| 146 | Root.DevToolsContext.globalInstance().delete(Settings); |
no test coverage detected