Skip to content

Commit

Permalink
Removed ReactorWithEffects.MutationWithEffect (#95)
Browse files Browse the repository at this point in the history
* Removed ReactorWithEffects.MutationWithEffect
* Bumped to version 0.9.5
* Corrected compile issue with tests
  • Loading branch information
ggrell authored Nov 12, 2020
1 parent ecf1ee1 commit 2e09b7f
Show file tree
Hide file tree
Showing 15 changed files with 18 additions and 540 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ task clean(type: Delete) {
subprojects {
group = "com.gyurigrell"
def isRelease = Boolean.valueOf(project.hasProperty("release") ? project.property("release") as String : "false")
version = "0.9.0" + (isRelease ? "" : "-SNAPSHOT")
version = "0.9.5" + (isRelease ? "" : "-SNAPSHOT")

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
kotlinOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import rx.android.schedulers.AndroidSchedulers
* Specialized implementation of [ReactorWithEffects] that ensures [effect] and [state] Observables emit on
* [AndroidSchedulers.mainThread]
*/
abstract class AndroidReactorWithEffects<Action, Mutation : ReactorWithEffects.MutationWithEffect<Effect>, State, Effect>(
abstract class AndroidReactorWithEffects<Action, Mutation, State, Effect>(
initialState: State
) : ReactorWithEffects<Action, Mutation, State, Effect>(initialState) {
override fun transformEffect(effect: Observable<Effect>): Observable<Effect> = effect.observeOn(AndroidSchedulers.mainThread())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

package com.gyurigrell.rxreactor1

import com.gyurigrell.rxreactor1.ReactorWithEffects.MutationWithEffect
import com.jakewharton.rxrelay.PublishRelay
import rx.Observable

Expand All @@ -26,7 +25,7 @@ import rx.Observable
* @param Effect the type of the effect that is emitted for side-effects that don't modify state
* @property initialState the initial state of the reactor, from which the {@see currentState} will be initialized.
*/
abstract class ReactorWithEffects<Action, Mutation : ReactorWithEffects.MutationWithEffect<Effect>, State, Effect>(
abstract class ReactorWithEffects<Action, Mutation, State, Effect>(
initialState: State
) : Reactor<Action, Mutation, State>(initialState) {
/**
Expand All @@ -36,19 +35,6 @@ abstract class ReactorWithEffects<Action, Mutation : ReactorWithEffects.Mutation

private val effectRelay: PublishRelay<Effect> = PublishRelay.create()

/**
* Checks to see if the mutation has an effect set. If it does, emits it via [ReactorWithEffects.effectRelay] and
* swallows the [Mutation], otherwise lets the [Mutation] pass through.
*/
override fun transformMutation(mutation: Observable<Mutation>): Observable<Mutation> = mutation.flatMap { m ->
// If its a TriggerEffect mutation, emit it as an Effect and prevent State emission
if (m.effect != null) {
effectRelay.call(m.effect)
return@flatMap Observable.empty<Mutation>()
}
Observable.just(m)
}

/**
* Override to modify the effect observable
*/
Expand All @@ -69,16 +55,4 @@ abstract class ReactorWithEffects<Action, Mutation : ReactorWithEffects.Mutation
protected fun emitEffect(vararg effect: Effect) {
Observable.from(effect).subscribe(effectRelay).also { subscriptions.add(it) }
}

/**
* The interface that needs to be applied to the [Mutation] sealed class defined in this [ReactorWithEffects]. It
* applies a field named [effect] which defaults to `null`, meaning that mutation doesn't emit effects. Generally
* there should only be a single mutation that has an override where it provides an effect.
* @param Effect this is just the [Effect] type defined in the reactor.
*/
@Deprecated("Prefer calling `emitEffect()` function instead")
interface MutationWithEffect<Effect> {
val effect: Effect?
get() = null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class ReactorWithEffectsTests {
data class ActionFiresEffectWithValue(val theValue: String) : Action()
}

sealed class Mutation : MutationWithEffect<Effect> {
sealed class Mutation {
object SimpleActionMutation : Mutation()
data class ActionWithValueMutation(val theValue: String) : Mutation()
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers
* Specialized implementation of [ReactorWithEffects] that ensures [effect] and [state] Observables emit on
* [AndroidSchedulers.mainThread]
*/
abstract class AndroidReactorWithEffects<Action, Mutation : ReactorWithEffects.MutationWithEffect<Effect>, State, Effect>(
abstract class AndroidReactorWithEffects<Action, Mutation, State, Effect>(
initialState: State
) : ReactorWithEffects<Action, Mutation, State, Effect>(initialState) {
override fun transformEffect(effect: Observable<Effect>): Observable<Effect> = effect.observeOn(AndroidSchedulers.mainThread())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

package com.gyurigrell.rxreactor2

import com.gyurigrell.rxreactor2.ReactorWithEffects.MutationWithEffect
import com.jakewharton.rxrelay2.PublishRelay
import io.reactivex.Observable

Expand All @@ -26,7 +25,7 @@ import io.reactivex.Observable
* @param Effect the type of the effect that is emitted for side-effects that don't modify state
* @property initialState the initial state of the reactor, from which the {@see currentState} will be initialized.
*/
abstract class ReactorWithEffects<Action, Mutation : MutationWithEffect<Effect>, State, Effect>(
abstract class ReactorWithEffects<Action, Mutation, State, Effect>(
initialState: State
) : Reactor<Action, Mutation, State>(initialState) {
/**
Expand All @@ -36,20 +35,6 @@ abstract class ReactorWithEffects<Action, Mutation : MutationWithEffect<Effect>,

private val effectRelay: PublishRelay<Effect> = PublishRelay.create()

/**
* Checks to see if the mutation has an effect set. If it does, emits it via [ReactorWithEffects.effectRelay] and
* swallows the [Mutation], otherwise lets the [Mutation] pass through.
*/
override fun transformMutation(mutation: Observable<Mutation>): Observable<Mutation> = mutation.flatMap { m ->
// If its a mutation for triggering an effect, emit it as an Effect and prevent State changes
val effect: Effect? = m.effect
if (effect != null) {
effectRelay.accept(effect)
return@flatMap Observable.empty<Mutation>()
}
Observable.just(m)
}

/**
* Override to modify the effect observable
*/
Expand All @@ -70,16 +55,4 @@ abstract class ReactorWithEffects<Action, Mutation : MutationWithEffect<Effect>,
protected fun emitEffect(vararg effect: Effect) {
Observable.fromIterable(effect.asIterable()).subscribe(effectRelay).also { subscriptions.add(it) }
}

/**
* The interface that needs to be applied to the [Mutation] sealed class defined in this [ReactorWithEffects]. It
* applies a field named [effect] which defaults to `null`, meaning that mutation doesn't emit effects. Generally
* there should only be a single mutation that has an override where it provides an effect.
* @param Effect this is just the [Effect] type defined in the reactor.
*/
@Deprecated("Prefer calling `emitEffect()` function instead")
interface MutationWithEffect<Effect> {
val effect: Effect?
get() = null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class ReactorWithEffectsTests {
data class ActionFiresEffectWithValue(val theValue: String) : Action()
}

sealed class Mutation : MutationWithEffect<Effect> {
sealed class Mutation {
object SimpleActionMutation : Mutation()
data class ActionWithValueMutation(val theValue: String) : Mutation()
}
Expand Down
Loading

0 comments on commit 2e09b7f

Please sign in to comment.