Class RxMobius.SubtypeEffectHandlerBuilder<F,​E>

  • Enclosing class:
    RxMobius

    public static class RxMobius.SubtypeEffectHandlerBuilder<F,​E>
    extends java.lang.Object
    Builder 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 using RxMobius.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 Detail

      • add

        @Deprecated
        public <G extends FRxMobius.SubtypeEffectHandlerBuilder<F,​E> add​(java.lang.Class<G> effectClass,
                                                                                 rx.Observable.Transformer<G,​E> effectHandler)
        Add an Observable.Transformer for 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 handle
        effectHandler - 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 FRxMobius.SubtypeEffectHandlerBuilder<F,​E> add​(java.lang.Class<G> effectClass,
                                                                                 rx.functions.Action0 action)
        Deprecated.
        Add an Action0 for 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 handle
        action - 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 FRxMobius.SubtypeEffectHandlerBuilder<F,​E> add​(java.lang.Class<G> effectClass,
                                                                                 rx.functions.Action0 action,
                                                                                 rx.Scheduler scheduler)
        Add an Action0 for 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 handle
        action - the action that should be invoked for the effect
        scheduler - 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 FRxMobius.SubtypeEffectHandlerBuilder<F,​E> add​(java.lang.Class<G> effectClass,
                                                                                 rx.functions.Action1<G> action)
        Add an Action1 for 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 handle
        action - 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 FRxMobius.SubtypeEffectHandlerBuilder<F,​E> add​(java.lang.Class<G> effectClass,
                                                                                 rx.functions.Action1<G> action,
                                                                                 rx.Scheduler scheduler)
        Add an Action1 for 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 handle
        action - the action that should be invoked for the effect
        scheduler - 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 FRxMobius.SubtypeEffectHandlerBuilder<F,​E> addFunction​(java.lang.Class<G> effectClass,
                                                                                         com.spotify.mobius.functions.Function<G,​E> function)
        Add a Func1 for 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 handle
        function - 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 FRxMobius.SubtypeEffectHandlerBuilder<F,​E> addFunction​(java.lang.Class<G> effectClass,
                                                                                         com.spotify.mobius.functions.Function<G,​E> function,
                                                                                         rx.Scheduler scheduler)
        Add a Func1 for 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 handle
        function - the function that should be invoked for the effect
        scheduler - 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 FRxMobius.SubtypeEffectHandlerBuilder<F,​E> addTransformer​(java.lang.Class<G> effectClass,
                                                                                            rx.Observable.Transformer<G,​E> effectHandler)
        Add an Observable.Transformer for 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 handle
        effectHandler - 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 FRxMobius.SubtypeEffectHandlerBuilder<F,​E> addAction​(java.lang.Class<G> effectClass,
                                                                                       rx.functions.Action0 action)
        Add an Action0 for 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 handle
        action - 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 FRxMobius.SubtypeEffectHandlerBuilder<F,​E> addAction​(java.lang.Class<G> effectClass,
                                                                                       rx.functions.Action0 action,
                                                                                       rx.Scheduler scheduler)
        Add an Action0 for 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 handle
        action - the action that should be invoked for the effect
        scheduler - 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 FRxMobius.SubtypeEffectHandlerBuilder<F,​E> addConsumer​(java.lang.Class<G> effectClass,
                                                                                         rx.functions.Action1<G> consumer)
        Add an Action1 for 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 handle
        consumer - 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 FRxMobius.SubtypeEffectHandlerBuilder<F,​E> addConsumer​(java.lang.Class<G> effectClass,
                                                                                         rx.functions.Action1<G> consumer,
                                                                                         rx.Scheduler scheduler)
        Add an Action1 for 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 handle
        consumer - the consumer that should be invoked for the effect
        scheduler - 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.
      • build

        public rx.Observable.Transformer<F,​E> build()