Reusable properties
Reusable properties introduced to address the problem described in issue #14
Reusable properties survive MapMemory.clear()
call. It will not be removed from cache, but will be cleared instead. Reusable properties are especially useful for reactive types like Flow
. You don't need to resubscribe to flow after MapMemory was cleared.
val flow by memory.sharedFlow<Int>()
// Subscribe to flow
flow.onEach(::println).launchIn(coroutineScope)
// And then clear MapMemory
memory.crear()
// Emitted value will be printed because the flow
// is the same as before memory clear
flow.emit(1)
You can create reusable property using operator invoke
with clear
lambda:
class Counter {
fun reset() = { /*...*/ }
}
val counter: Counter by memory(clear = { it.reset() }) { Counter() }
Many of default accessors are already turned into reusable: mutableList
, mutableMap
, reactiveMutableMap
, stateFlow
, sharedFlow
, behaviorSubject
, publishSubject
.
Changes
⚠️ Deprecated functions removed:MapMemory.nullable
,MapMemory.reactiveMap
,ReactiveMutableMap.getStream
,ReactiveMutableMap.getAll
,ReactiveMutableMap.getAllStream
- Added parameter
defaultValue
to most of reusable properties:mutableList
,mutableMap
,reactiveMutableMap
,behaviorSubject
. ⚠️ mapmemory-rxjava:ReplayStrategy
was removed. Please let us know if this change affected you: #20
Fixes
- ReactiveMutableMap: initial empty map is not emitted (#15)
Dependencies
- mapmemory: Kotlin
1.4.30
→1.8.20
- mapmemory-coroutines: kotlinx.coroutines
1.4.2
→1.6.4
- mapmemory-rxjava3: RxJava
3.0.11
→3.1.6
Housekeeping
- infrastructure
0.8.2
→0.18.1
- detekt
1.16.0
→1.22.0
- Gradle
6.8.3
→8.1.1
- binary-compatibility-validator
0.5.0
→0.13.1
Full Changelog: v2.0...v2.1