Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.arkivanov.mvikotlin.extensions.coroutines

import com.arkivanov.mvikotlin.core.annotations.MainThread
import com.arkivanov.mvikotlin.core.store.Bootstrapper
import com.arkivanov.mvikotlin.core.store.Store
import com.arkivanov.mvikotlin.utils.internal.atomic
Expand Down Expand Up @@ -32,10 +33,11 @@ abstract class CoroutineBootstrapper<Action : Any>(
}

/**
* Dispatches the `Action` to the [Store]
* Dispatches the `Action` to the [Store]. Must be called on the main thread.
*
* @param action an `Action` to be dispatched
*/
@MainThread
protected fun dispatch(action: Action) {
actionConsumer.requireValue().invoke(action)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.arkivanov.mvikotlin.extensions.coroutines

import com.arkivanov.mvikotlin.core.annotations.MainThread
import com.arkivanov.mvikotlin.core.utils.ExperimentalMviKotlinApi
import kotlinx.coroutines.CoroutineScope

Expand All @@ -16,8 +17,10 @@ interface CoroutineBootstrapperScope<in Action : Any> : CoroutineScope {

/**
* Dispatches the [Action] to the [Store][com.arkivanov.mvikotlin.core.store.Store].
* Must be called on the main thread.
*
* @param action an [Action] to be dispatched.
*/
@MainThread
fun dispatch(action: Action)
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ open class CoroutineExecutor<in Intent : Any, in Action : Any, in State : Any, M
/**
* Dispatches the provided `Message` to the [Reducer].
* The updated `State` will be available immediately after this method returns.
* Must be called on the main thread.
*
* @param message a `Message` to be dispatched to the `Reducer`
*/
Expand All @@ -80,7 +81,8 @@ open class CoroutineExecutor<in Intent : Any, in Action : Any, in State : Any, M
}

/**
* Sends the provided `Label` to the [Store] for publication
* Sends the provided `Label` to the [Store] for publication.
* Must be called on the main thread.
*
* @param label a `Label` to be published
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.arkivanov.mvikotlin.extensions.coroutines

import com.arkivanov.mvikotlin.core.annotations.MainThread
import com.arkivanov.mvikotlin.core.store.Bootstrapper
import com.arkivanov.mvikotlin.core.store.Store
import com.arkivanov.mvikotlin.utils.internal.atomic
Expand Down Expand Up @@ -31,10 +32,11 @@ abstract class SuspendBootstrapper<Action : Any>(
}

/**
* Dispatches the `Action` to the [Store]
* Dispatches the `Action` to the [Store]. Must be called on the main thread.
*
* @param action an `Action` to be dispatched
*/
@MainThread
protected fun dispatch(action: Action) {
actionConsumer.requireValue().invoke(action)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import com.arkivanov.mvikotlin.core.store.Store
import com.arkivanov.mvikotlin.rx.Disposable
import com.arkivanov.mvikotlin.rx.Observer
import com.arkivanov.mvikotlin.rx.internal.Disposable
import com.arkivanov.mvikotlin.utils.internal.atomic
import com.arkivanov.mvikotlin.utils.internal.getValue
import com.arkivanov.mvikotlin.utils.internal.setValue
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
Expand All @@ -25,10 +22,10 @@ class StateFlowTest {
val store = TestStore()
val flow = store.stateFlow
val scope = CoroutineScope(Dispatchers.Unconfined)
var items: List<Int> by atomic(emptyList())
val items = ArrayList<Int>()

scope.launch {
flow.collect { items = items + it }
flow.collect { items += it }
}

store.stateObserver?.onNext(1)
Expand Down Expand Up @@ -57,7 +54,7 @@ class StateFlowTest {
override val state: Int = 0
override val isDisposed: Boolean = false

var stateObserver: Observer<Int>? by atomic(null)
var stateObserver: Observer<Int>? = null
private set

override fun states(observer: Observer<Int>): Disposable {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.arkivanov.mvikotlin.extensions.reaktive

import com.arkivanov.mvikotlin.core.annotations.MainThread
import com.arkivanov.mvikotlin.core.store.Bootstrapper
import com.arkivanov.mvikotlin.core.store.Store
import com.arkivanov.mvikotlin.utils.internal.atomic
Expand All @@ -26,10 +27,11 @@ abstract class ReaktiveBootstrapper<Action : Any> : Bootstrapper<Action>, Dispos
}

/**
* Dispatches the `Action` to the [Store]
* Dispatches the `Action` to the [Store]. Must be called on the main thread.
*
* @param action an `Action` to be dispatched
*/
@MainThread
protected fun dispatch(action: Action) {
actionConsumer.requireValue().invoke(action)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ open class ReaktiveExecutor<in Intent : Any, in Action : Any, in State : Any, Me
/**
* Dispatches the provided `Message` to the [Reducer].
* The updated `State` will be available immediately after this method returns.
* Must be called on the main thread.
*
* @param message a `Message` to be dispatched to the `Reducer`
*/
Expand All @@ -76,7 +77,8 @@ open class ReaktiveExecutor<in Intent : Any, in Action : Any, in State : Any, Me
}

/**
* Sends the provided `Label` to the [Store] for publication
* Sends the provided `Label` to the [Store] for publication.
* Must be called on the main thread.
*
* @param label a `Label` to be published
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ package com.arkivanov.mvikotlin.logging.store
import com.arkivanov.mvikotlin.core.store.StoreEventType
import com.arkivanov.mvikotlin.logging.logger.LogFormatter
import com.arkivanov.mvikotlin.logging.logger.Logger
import com.arkivanov.mvikotlin.utils.internal.atomic
import com.arkivanov.mvikotlin.utils.internal.getValue
import com.arkivanov.mvikotlin.utils.internal.setValue
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue
Expand All @@ -15,7 +12,7 @@ internal class TestLogger(
private val storeName: String
) : Logger {

private var logs by atomic(emptyList<String>())
private var logs = ArrayList<String>()

override fun log(text: String) {
this.logs += text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import com.arkivanov.mvikotlin.core.store.Reducer
import com.arkivanov.mvikotlin.core.store.Store
import com.arkivanov.mvikotlin.rx.Disposable
import com.arkivanov.mvikotlin.rx.Observer
import com.arkivanov.mvikotlin.utils.internal.atomic
import com.arkivanov.mvikotlin.utils.internal.getValue
import com.arkivanov.mvikotlin.utils.internal.setValue

internal class TestStore<in Intent : Any, Action : Any, State : Any, in Message : Any, Label : Any>(
initialState: State,
Expand All @@ -17,7 +14,7 @@ internal class TestStore<in Intent : Any, Action : Any, State : Any, in Message
private val reducer: Reducer<State, Message>
) : Store<Intent, State, Label> {

override var state: State by atomic(initialState)
override var state: State = initialState
private set

override val isDisposed: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import com.arkivanov.mvikotlin.rx.Observer
import com.arkivanov.mvikotlin.rx.internal.BehaviorSubject
import com.arkivanov.mvikotlin.rx.internal.PublishSubject
import com.arkivanov.mvikotlin.rx.observer
import com.arkivanov.mvikotlin.utils.internal.atomic

internal class DefaultStore<in Intent : Any, in Action : Any, in Message : Any, out State : Any, Label : Any>(
initialState: State,
Expand All @@ -24,16 +23,16 @@ internal class DefaultStore<in Intent : Any, in Action : Any, in Message : Any,
override val state: State get() = stateSubject.value
override val isDisposed: Boolean get() = !stateSubject.isActive
private val labelSubject = PublishSubject<Label>()
private val isInitialized = atomic(false)
private var isInitialized = false

override fun init() {
assertOnMainThread()

if (isInitialized.value) {
if (isInitialized) {
return
}

isInitialized.value = true
isInitialized = true

intentSubject.subscribe(observer(onNext = ::onIntent))

Expand Down
Loading