From 10e03bb95105cae7f9b1da53f9c9daa3eb2f2340 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 14 Dec 2023 23:56:56 +0600 Subject: [PATCH] allow to create own Diff with constructor --- CHANGELOG.md | 3 +++ .../kotlin/dev/inmo/micro_utils/common/DiffUtils.kt | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e196401dbe..a692feb380a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.20.22 +* `Common`: + * Add opportunity to create own `Diff` with base constructor + ## 0.20.21 * `Resources`: diff --git a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/DiffUtils.kt b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/DiffUtils.kt index 4f2f2635ac4..f4c8008223d 100644 --- a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/DiffUtils.kt +++ b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/DiffUtils.kt @@ -27,7 +27,7 @@ private inline fun getObject( * @see calculateDiff */ @Serializable -data class Diff internal constructor( +data class Diff @Warning(warning) constructor( val removed: List<@Serializable(IndexedValueSerializer::class) IndexedValue>, /** * Old-New values pairs @@ -36,6 +36,10 @@ data class Diff internal constructor( val added: List<@Serializable(IndexedValueSerializer::class) IndexedValue> ) { fun isEmpty(): Boolean = removed.isEmpty() && replaced.isEmpty() && added.isEmpty() + + companion object { + private const val warning = "This feature can be changed without any warranties. Use with caution and only in case you know what you are doing" + } } fun emptyDiff(): Diff = Diff(emptyList(), emptyList(), emptyList())