Skip to content

Commit

Permalink
Clean up delegate helper signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
seadowg committed Dec 5, 2024
1 parent 60cbc2c commit 02cfd1e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ abstract class DataService(private val appState: AppState, private val onUpdate:
onUpdate?.invoke()
}

protected fun <T> data(key: String, default: T): DataDelegate<T> {
val data = Data(appState, key, default)
return DataDelegate(data)
}

protected fun <T> data(key: String, default: T, updater: () -> T): DataDelegate<T> {
val data = attachData(key, default) { updater() }
return DataDelegate(data)
Expand All @@ -42,11 +47,6 @@ abstract class DataService(private val appState: AppState, private val onUpdate:
return DataDelegate(data)
}

protected fun <T> qualifiedData(key: String, default: T): DataDelegate<T> {
val data = Data(appState, key, default)
return DataDelegate(data)
}

private fun <T> attachData(key: String, default: T, updater: (String?) -> T): Data<T> {
val data = Data(appState, key, default)
dataUpdaters.add(DataUpdater(data, updater))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class FormsDataService(
projectDependencies.formsRepository.all
}

private val syncing by qualifiedData(DataKeys.SYNC_STATUS_SYNCING, false)
private val serverError by qualifiedData<FormSourceException?>(DataKeys.SYNC_STATUS_ERROR, null)
private val diskError by qualifiedData<String?>(DataKeys.DISK_ERROR, null)
private val syncing by data(DataKeys.SYNC_STATUS_SYNCING, false)
private val serverError by data<FormSourceException?>(DataKeys.SYNC_STATUS_ERROR, null)
private val diskError by data<String?>(DataKeys.DISK_ERROR, null)

fun getForms(projectId: String): Flow<List<Form>> {
return forms.get(projectId)
Expand Down

0 comments on commit 02cfd1e

Please sign in to comment.