Skip to content

Commit e6786d2

Browse files
ajesh-nAjesh
andauthored
Make bookkeeper optional (#529)
Signed-off-by: Ajesh <ajesh_nair@ymail.com> Co-authored-by: Ajesh <aj@Ajeshs-MacBook-Pro.local>
1 parent 99e7f2b commit e6786d2

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/StoreBuilder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ interface StoreBuilder<Key : Any, Network : Any, Output : Any, Local : Any> {
2727

2828
fun <Response : Any> build(
2929
updater: Updater<Key, Output, Response>,
30-
bookkeeper: Bookkeeper<Key>
30+
bookkeeper: Bookkeeper<Key>? = null
3131
): MutableStore<Key, Output>
3232

3333
/**

store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/RealMutableStore.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import org.mobilenativefoundation.store.store5.internal.result.EagerConflictReso
3030
internal class RealMutableStore<Key : Any, Network : Any, Output : Any, Local : Any>(
3131
private val delegate: RealStore<Key, Network, Output, Local>,
3232
private val updater: Updater<Key, Output, *>,
33-
private val bookkeeper: Bookkeeper<Key>,
33+
private val bookkeeper: Bookkeeper<Key>?,
3434
) : MutableStore<Key, Output>, Clear.Key<Key> by delegate, Clear.All by delegate {
3535

3636
private val storeLock = Mutex()
@@ -107,9 +107,9 @@ internal class RealMutableStore<Key : Any, Network : Any, Output : Any, Local :
107107
created = request.created,
108108
updaterResult = updaterResult
109109
)
110-
bookkeeper.clear(request.key)
110+
bookkeeper?.clear(request.key)
111111
} else {
112-
bookkeeper.setLastFailedSync(request.key)
112+
bookkeeper?.setLastFailedSync(request.key)
113113
}
114114

115115
return updaterResult
@@ -199,7 +199,7 @@ internal class RealMutableStore<Key : Any, Network : Any, Output : Any, Local :
199199
}
200200

201201
private suspend fun conflictsMightExist(key: Key): Boolean {
202-
val lastFailedSync = bookkeeper.getLastFailedSync(key)
202+
val lastFailedSync = bookkeeper?.getLastFailedSync(key)
203203
return lastFailedSync != null || writeRequestsQueueIsEmpty(key).not()
204204
}
205205

@@ -215,7 +215,7 @@ internal class RealMutableStore<Key : Any, Network : Any, Output : Any, Local :
215215
withThreadSafety(key) {
216216
val latest = delegate.latestOrNull(key)
217217
when {
218-
latest == null || conflictsMightExist(key).not() -> EagerConflictResolutionResult.Success.NoConflicts
218+
latest == null || bookkeeper == null || conflictsMightExist(key).not() -> EagerConflictResolutionResult.Success.NoConflicts
219219
else -> {
220220
try {
221221
val updaterResult = updater.post(key, latest).also { updaterResult ->

store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/RealStoreBuilder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ internal class RealStoreBuilder<Key : Any, Network : Any, Output : Any, Local :
7070

7171
override fun <UpdaterResult : Any> build(
7272
updater: Updater<Key, Output, UpdaterResult>,
73-
bookkeeper: Bookkeeper<Key>
73+
bookkeeper: Bookkeeper<Key>?
7474
): MutableStore<Key, Output> =
7575
build().asMutableStore<Key, Network, Output, Local, UpdaterResult>(
7676
updater = updater,

store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/extensions/store.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ suspend fun <Key : Any, Output : Any> Store<Key, Output>.fresh(key: Key) =
3838
@Suppress("UNCHECKED_CAST")
3939
fun <Key : Any, Network : Any, Output : Any, Local : Any, Response : Any> Store<Key, Output>.asMutableStore(
4040
updater: Updater<Key, Output, Response>,
41-
bookkeeper: Bookkeeper<Key>
41+
bookkeeper: Bookkeeper<Key>?
4242
): MutableStore<Key, Output> {
4343
val delegate = this as? RealStore<Key, Network, Output, Local>
4444
?: throw Exception("MutableStore requires Store to be built using StoreBuilder")

0 commit comments

Comments
 (0)