(
key: SystemConfigKey,
defaultValue: WithAsyncValue<Exclude<T, undefined>>
)
| 145 | } |
| 146 | |
| 147 | private _get<T extends string | number | boolean | object>( |
| 148 | key: SystemConfigKey, |
| 149 | defaultValue: WithAsyncValue<Exclude<T, undefined>> |
| 150 | ): Promise<T> { |
| 151 | if (this.cache.has(key)) { |
| 152 | const val = this.cache.get(key); |
| 153 | return Promise.resolve(val === undefined ? this.resolveDefault<T>(defaultValue) : (val as T)); |
| 154 | } |
| 155 | const storage = this.getStorage(key); |
| 156 | return storage.get(key).then((val) => { |
| 157 | if (val !== undefined) { |
| 158 | this.cache.set(key, val); |
| 159 | return val as T; |
| 160 | } |
| 161 | // 对 local key,回退读取 sync storage(兼容旧版本数据迁移) |
| 162 | if (this.isLocalKey(key)) { |
| 163 | return this.transferSyncToLocal<T>(key, defaultValue); |
| 164 | } |
| 165 | this.cache.set(key, val); |
| 166 | return this.resolveDefault<T>(defaultValue); |
| 167 | }); |
| 168 | } |
| 169 | |
| 170 | public get<T extends SystemConfigKey>(key: T): Promise<SystemConfigValueType<T>> { |
| 171 | const funcName = `get${toCamelCase(key)}`; |
no test coverage detected