Skip to content

Commit dc607be

Browse files
committed
Make source parameter optional and nullable in the ReducingModel constructor
1 parent d12a1d4 commit dc607be

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

krescent-core/src/main/kotlin/dev/helight/krescent/model/ReducingModel.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ interface ReducingModel<S : Any> {
2929
* Per default, this uses reflections to find the proper serializer for the current state class.
3030
*/
3131
val serializer: KSerializer<Any>
32-
get() = Json.Default.serializersModule.serializer(currentState::class.java)
32+
get() = Json.serializersModule.serializer(currentState::class.java)
3333

3434
/**
3535
* Reduces the current state with the given event and returns the new state.
@@ -65,14 +65,14 @@ interface ReducingModel<S : Any> {
6565

6666
override suspend fun createCheckpoint(bucket: CheckpointBucket) {
6767
val serializer = model.serializer
68-
bucket["state"] = Json.Default.encodeToJsonElement(serializer, model.currentState)
68+
bucket["state"] = Json.encodeToJsonElement(serializer, model.currentState)
6969
}
7070

7171
@Suppress("UNCHECKED_CAST")
7272
override suspend fun restoreCheckpoint(bucket: CheckpointBucket) {
7373
val data = bucket["state"] ?: error("No recorded state found in checkpoint bucket")
7474
val serializer = model.serializer
75-
model.currentState = Json.Default.decodeFromJsonElement(serializer, data) as S
75+
model.currentState = Json.decodeFromJsonElement(serializer, data) as S
7676
}
7777
}
7878
}
@@ -93,7 +93,7 @@ abstract class ReducingWriteModel<S : Any>(
9393
namespace: String,
9494
revision: Int,
9595
catalog: EventCatalog,
96-
source: StreamingEventSource,
96+
source: StreamingEventSource? = null,
9797
publisher: EventPublisher? = null,
9898
configure: suspend EventModelBuilder.() -> Unit = { },
9999
) : WriteModelBase(namespace, revision, catalog, source, publisher, configure), ReducingModel<S> {

0 commit comments

Comments
 (0)