Class RxMobius.SubtypeEffectHandlerBuilder<F,E>
- java.lang.Object
-
- com.spotify.mobius.rx.RxMobius.SubtypeEffectHandlerBuilder<F,E>
-
- Enclosing class:
- RxMobius
public static class RxMobius.SubtypeEffectHandlerBuilder<F,E> extends java.lang.ObjectBuilder for a type-routing effect handler.Register handlers for different subtypes of F using the add(...) methods, and call
build()to create an instance of the effect handler. You can then create a loop with the router as the effect handler usingRxMobius.loop(Update, Observable.Transformer).The handler will look at the type of each incoming effect object and try to find a registered handler for that particular subtype of F. If a handler is found, it will be given the effect object, otherwise an exception will be thrown.
All the classes that the effect router know about must have a common type F. Note that instances of the builder are mutable and not thread-safe.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description <G extends F>
RxMobius.SubtypeEffectHandlerBuilder<F,E>add(java.lang.Class<G> effectClass, rx.functions.Action0 action)Deprecated.<G extends F>
RxMobius.SubtypeEffectHandlerBuilder<F,E>add(java.lang.Class<G> effectClass, rx.functions.Action0 action, rx.Scheduler scheduler)Deprecated.<G extends F>
RxMobius.SubtypeEffectHandlerBuilder<F,E>add(java.lang.Class<G> effectClass, rx.functions.Action1<G> action)Deprecated.<G extends F>
RxMobius.SubtypeEffectHandlerBuilder<F,E>add(java.lang.Class<G> effectClass, rx.functions.Action1<G> action, rx.Scheduler scheduler)Deprecated.<G extends F>
RxMobius.SubtypeEffectHandlerBuilder<F,E>add(java.lang.Class<G> effectClass, rx.Observable.Transformer<G,E> effectHandler)Deprecated.<G extends F>
RxMobius.SubtypeEffectHandlerBuilder<F,E>addAction(java.lang.Class<G> effectClass, rx.functions.Action0 action)Add anAction0for handling effects of a given type.<G extends F>
RxMobius.SubtypeEffectHandlerBuilder<F,E>addAction(java.lang.Class<G> effectClass, rx.functions.Action0 action, rx.Scheduler scheduler)Add anAction0for handling effects of a given type.<G extends F>
RxMobius.SubtypeEffectHandlerBuilder<F,E>addConsumer(java.lang.Class<G> effectClass, rx.functions.Action1<G> consumer)Add anAction1for handling effects of a given type.<G extends F>
RxMobius.SubtypeEffectHandlerBuilder<F,E>addConsumer(java.lang.Class<G> effectClass, rx.functions.Action1<G> consumer, rx.Scheduler scheduler)Add anAction1for handling effects of a given type.<G extends F>
RxMobius.SubtypeEffectHandlerBuilder<F,E>addFunction(java.lang.Class<G> effectClass, com.spotify.mobius.functions.Function<G,E> function)Add aFunc1for handling effects of a given type.<G extends F>
RxMobius.SubtypeEffectHandlerBuilder<F,E>addFunction(java.lang.Class<G> effectClass, com.spotify.mobius.functions.Function<G,E> function, rx.Scheduler scheduler)Add aFunc1for handling effects of a given type.<G extends F>
RxMobius.SubtypeEffectHandlerBuilder<F,E>addTransformer(java.lang.Class<G> effectClass, rx.Observable.Transformer<G,E> effectHandler)Add anObservable.Transformerfor handling effects of a given type.rx.Observable.Transformer<F,E>build()RxMobius.SubtypeEffectHandlerBuilder<F,E>withFatalErrorHandler(rx.functions.Func1<rx.Observable.Transformer<? extends F,E>,rx.functions.Action1<java.lang.Throwable>> onErrorFunction)Optionally set a shared error handler in case a handler throws an uncaught exception.
-
-
-
Method Detail
-
add
@Deprecated public <G extends F> RxMobius.SubtypeEffectHandlerBuilder<F,E> add(java.lang.Class<G> effectClass, rx.Observable.Transformer<G,E> effectHandler)
Deprecated.Add anObservable.Transformerfor handling effects of a given type. The handler will receive all effect objects that extend the given class.Adding handlers for two effect classes where one is a super-class of the other is considered a collision and is not allowed. Registering the same class twice is also considered a collision.
- Type Parameters:
G- the effect class as a type parameter- Parameters:
effectClass- the effect class to handleeffectHandler- the effect handler for the given effect class- Returns:
- this builder
- Throws:
java.lang.IllegalArgumentException- if there is a handler collision
-
add
@Deprecated public <G extends F> RxMobius.SubtypeEffectHandlerBuilder<F,E> add(java.lang.Class<G> effectClass, rx.functions.Action0 action)
Deprecated.Add anAction0for handling effects of a given type. The action will be invoked once for every received effect object that extends the given class.Adding handlers for two effect classes where one is a super-class of the other is considered a collision and is not allowed. Registering the same class twice is also considered a collision.
- Type Parameters:
G- the effect class as a type parameter- Parameters:
effectClass- the class to handleaction- the action that should be invoked for the effect- Returns:
- this builder
- Throws:
java.lang.IllegalArgumentException- if there is a handler collision
-
add
@Deprecated public <G extends F> RxMobius.SubtypeEffectHandlerBuilder<F,E> add(java.lang.Class<G> effectClass, rx.functions.Action0 action, rx.Scheduler scheduler)
Deprecated.Add anAction0for handling effects of a given type. The action will be invoked once for every received effect object that extends the given class.Adding handlers for two effect classes where one is a super-class of the other is considered a collision and is not allowed. Registering the same class twice is also considered a collision.
- Type Parameters:
G- the effect class as a type parameter- Parameters:
effectClass- the class to handleaction- the action that should be invoked for the effectscheduler- the scheduler that should be used to invoke the action- Returns:
- this builder
- Throws:
java.lang.IllegalArgumentException- if there is a handler collision
-
add
@Deprecated public <G extends F> RxMobius.SubtypeEffectHandlerBuilder<F,E> add(java.lang.Class<G> effectClass, rx.functions.Action1<G> action)
Deprecated.Add anAction1for handling effects of a given type. The action will be invoked once for every received effect object that extends the given class.Adding handlers for two effect classes where one is a super-class of the other is considered a collision and is not allowed. Registering the same class twice is also considered a collision.
- Type Parameters:
G- the effect class as a type parameter- Parameters:
effectClass- the class to handleaction- the action that should be invoked for the effect- Returns:
- this builder
- Throws:
java.lang.IllegalArgumentException- if there is a handler collision
-
add
@Deprecated public <G extends F> RxMobius.SubtypeEffectHandlerBuilder<F,E> add(java.lang.Class<G> effectClass, rx.functions.Action1<G> action, rx.Scheduler scheduler)
Deprecated.Add anAction1for handling effects of a given type. The action will be invoked once for every received effect object that extends the given class.Adding handlers for two effect classes where one is a super-class of the other is considered a collision and is not allowed. Registering the same class twice is also considered a collision.
- Type Parameters:
G- the effect class as a type parameter- Parameters:
effectClass- the class to handleaction- the action that should be invoked for the effectscheduler- the scheduler that should be used to invoke the action- Returns:
- this builder
- Throws:
java.lang.IllegalArgumentException- if there is a handler collision
-
addFunction
public <G extends F> RxMobius.SubtypeEffectHandlerBuilder<F,E> addFunction(java.lang.Class<G> effectClass, com.spotify.mobius.functions.Function<G,E> function)
Add aFunc1for handling effects of a given type. The function will be invoked once for every received effect object that extends the given class. The returned event will be forwarded to the Mobius loop.Adding handlers for two effect classes where one is a super-class of the other is considered a collision and is not allowed. Registering the same class twice is also considered a collision.
- Type Parameters:
G- the effect class as a type parameter- Parameters:
effectClass- the class to handlefunction- the function that should be invoked for the effect- Returns:
- this builder
- Throws:
java.lang.IllegalArgumentException- if there is a handler collision
-
addFunction
public <G extends F> RxMobius.SubtypeEffectHandlerBuilder<F,E> addFunction(java.lang.Class<G> effectClass, com.spotify.mobius.functions.Function<G,E> function, rx.Scheduler scheduler)
Add aFunc1for handling effects of a given type. The function will be invoked once for every received effect object that extends the given class. The returned event will be forwarded to the Mobius loop.Adding handlers for two effect classes where one is a super-class of the other is considered a collision and is not allowed. Registering the same class twice is also considered a collision.
- Type Parameters:
G- the effect class as a type parameter- Parameters:
effectClass- the class to handlefunction- the function that should be invoked for the effectscheduler- the scheduler that should be used when invoking the function- Returns:
- this builder
- Throws:
java.lang.IllegalArgumentException- if there is a handler collision
-
addTransformer
public <G extends F> RxMobius.SubtypeEffectHandlerBuilder<F,E> addTransformer(java.lang.Class<G> effectClass, rx.Observable.Transformer<G,E> effectHandler)
Add anObservable.Transformerfor handling effects of a given type. The handler will receive all effect objects that extend the given class.Adding handlers for two effect classes where one is a super-class of the other is considered a collision and is not allowed. Registering the same class twice is also considered a collision.
- Type Parameters:
G- the effect class as a type parameter- Parameters:
effectClass- the effect class to handleeffectHandler- the effect handler for the given effect class- Returns:
- this builder
- Throws:
java.lang.IllegalArgumentException- if there is a handler collision
-
addAction
public <G extends F> RxMobius.SubtypeEffectHandlerBuilder<F,E> addAction(java.lang.Class<G> effectClass, rx.functions.Action0 action)
Add anAction0for handling effects of a given type. The action will be invoked once for every received effect object that extends the given class.Adding handlers for two effect classes where one is a super-class of the other is considered a collision and is not allowed. Registering the same class twice is also considered a collision.
- Type Parameters:
G- the effect class as a type parameter- Parameters:
effectClass- the class to handleaction- the action that should be invoked for the effect- Returns:
- this builder
- Throws:
java.lang.IllegalArgumentException- if there is a handler collision
-
addAction
public <G extends F> RxMobius.SubtypeEffectHandlerBuilder<F,E> addAction(java.lang.Class<G> effectClass, rx.functions.Action0 action, rx.Scheduler scheduler)
Add anAction0for handling effects of a given type. The action will be invoked once for every received effect object that extends the given class.Adding handlers for two effect classes where one is a super-class of the other is considered a collision and is not allowed. Registering the same class twice is also considered a collision.
- Type Parameters:
G- the effect class as a type parameter- Parameters:
effectClass- the class to handleaction- the action that should be invoked for the effectscheduler- the scheduler that should be used to invoke the action- Returns:
- this builder
- Throws:
java.lang.IllegalArgumentException- if there is a handler collision
-
addConsumer
public <G extends F> RxMobius.SubtypeEffectHandlerBuilder<F,E> addConsumer(java.lang.Class<G> effectClass, rx.functions.Action1<G> consumer)
Add anAction1for handling effects of a given type. The action will be invoked once for every received effect object that extends the given class.Adding handlers for two effect classes where one is a super-class of the other is considered a collision and is not allowed. Registering the same class twice is also considered a collision.
- Type Parameters:
G- the effect class as a type parameter- Parameters:
effectClass- the class to handleconsumer- the consumer that should be invoked for the effect- Returns:
- this builder
- Throws:
java.lang.IllegalArgumentException- if there is a handler collision
-
addConsumer
public <G extends F> RxMobius.SubtypeEffectHandlerBuilder<F,E> addConsumer(java.lang.Class<G> effectClass, rx.functions.Action1<G> consumer, rx.Scheduler scheduler)
Add anAction1for handling effects of a given type. The action will be invoked once for every received effect object that extends the given class.Adding handlers for two effect classes where one is a super-class of the other is considered a collision and is not allowed. Registering the same class twice is also considered a collision.
- Type Parameters:
G- the effect class as a type parameter- Parameters:
effectClass- the class to handleconsumer- the consumer that should be invoked for the effectscheduler- the scheduler that should be used to invoke the action- Returns:
- this builder
- Throws:
java.lang.IllegalArgumentException- if there is a handler collision
-
withFatalErrorHandler
public RxMobius.SubtypeEffectHandlerBuilder<F,E> withFatalErrorHandler(rx.functions.Func1<rx.Observable.Transformer<? extends F,E>,rx.functions.Action1<java.lang.Throwable>> onErrorFunction)
Optionally set a shared error handler in case a handler throws an uncaught exception.The default is to use
RxJavaHooks.onError(Throwable). Note that any exception thrown by a handler is a fatal error and this method doesn't enable safe error handling, only configurable crash reporting.- Parameters:
onErrorFunction- a function that gets told which sub-transformer failed and should return an appropriate handler for exceptions thrown.
-
-