(
initialContent?: Content | (() => Content),
)
| 199 | // -- |
| 200 | |
| 201 | const load = async ( |
| 202 | initialContent?: Content | (() => Content), |
| 203 | ): Promise<Persister> => { |
| 204 | /*! istanbul ignore else */ |
| 205 | if (status != StatusValues.Saving) { |
| 206 | setStatus(StatusValues.Loading); |
| 207 | loads++; |
| 208 | await schedule(async () => { |
| 209 | await tryCatch( |
| 210 | async () => { |
| 211 | const content = await getPersisted(); |
| 212 | if (isArray(content)) { |
| 213 | setContentOrChanges(content); |
| 214 | } else if (isUndefined(content) && initialContent) { |
| 215 | setDefaultContent(initialContent); |
| 216 | } else if (!isUndefined(content)) { |
| 217 | errorNew(`Content is not an array: ${content}`); |
| 218 | } |
| 219 | }, |
| 220 | (error) => { |
| 221 | onIgnoredError?.(error); |
| 222 | if (initialContent) { |
| 223 | setDefaultContent(initialContent); |
| 224 | } |
| 225 | }, |
| 226 | ); |
| 227 | setStatus(StatusValues.Idle); |
| 228 | await saveAfterMutated(); |
| 229 | }); |
| 230 | } |
| 231 | return persister; |
| 232 | }; |
| 233 | |
| 234 | const startAutoLoad = async ( |
| 235 | initialContent?: Content | (() => Content), |
no test coverage detected
searching dependent graphs…