Skip to content

Commit bf88dd5

Browse files
committed
Fixed by childReactiveState to call onReactiveStateAttached(child)
1 parent 95216ef commit bf88dd5

File tree

4 files changed

+7
-9
lines changed

4 files changed

+7
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 5.12.0
4+
5+
* Fixed `by childReactiveState` to call `onReactiveStateAttached(child)` (the arguments were inverted).
6+
37
## 5.11.0
48

59
* Added `MutableStateFlow<T>.collectAsMutableState()` to create a two-way binding.

reactivestate-core/src/commonMain/kotlin/com/ensody/reactivestate/OnReactiveStateAttached.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,3 @@ package com.ensody.reactivestate
99
public interface OnReactiveStateAttached {
1010
public fun onReactiveStateAttached(reactiveState: ReactiveState<out ErrorEvents>)
1111
}
12-
13-
public fun ReactiveState<out ErrorEvents>.attachTo(owner: Any) {
14-
if (owner is OnReactiveStateAttached) {
15-
owner.onReactiveStateAttached(this)
16-
}
17-
}

reactivestate-core/src/commonMain/kotlin/com/ensody/reactivestate/ReactiveState.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public fun <E : ErrorEvents, P : ReactiveState<out E>, RS : ReactiveState<E>> P.
104104
launch(withLoading = null) {
105105
eventNotifier.emitAll(child.eventNotifier)
106106
}
107-
attachTo(child)
107+
(this as? OnReactiveStateAttached)?.onReactiveStateAttached(child)
108108
return WrapperProperty(child)
109109
}
110110

reactivestate/src/androidMain/kotlin/com/ensody/reactivestate/android/ReactiveViewModelExt.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import androidx.lifecycle.ViewModel
99
import androidx.lifecycle.viewModelScope
1010
import com.ensody.reactivestate.ErrorEvents
1111
import com.ensody.reactivestate.NamespacedStateFlowStore
12+
import com.ensody.reactivestate.OnReactiveStateAttached
1213
import com.ensody.reactivestate.ReactiveState
1314
import com.ensody.reactivestate.StateFlowStore
14-
import com.ensody.reactivestate.attachTo
1515
import kotlinx.coroutines.CoroutineScope
1616
import kotlin.collections.set
1717
import kotlin.reflect.KClass
@@ -47,7 +47,7 @@ public fun <E : ErrorEvents> Lazy<ReactiveState<E>>.attachLazyReactiveState(
4747
value.eventNotifier.handleEvents(handler, owner)
4848
}
4949
owner.launchOnceStateAtLeast(Lifecycle.State.CREATED) {
50-
value.attachTo(owner)
50+
(owner as? OnReactiveStateAttached)?.onReactiveStateAttached(value)
5151
}
5252
}
5353

0 commit comments

Comments
 (0)