Interface Store

  • All Superinterfaces:
    Dispatcher, GetState


    public interface Store
    extends GetState, Dispatcher
    The Store contains the application's state, reducer logic, middleware and listeners.
    • State represents the application state. The state is partition into state keys.
    • Reducer represents the logic to update the State. A reducer provides the functionality to update the state for a particular Action.
    • Middleware is a function that intercepts an Action and can enrich or alter it before reaching the Reducer.
    • Listener a function that gets called on state changes
    • Method Detail

      • reset

        void reset(State state)
        Resets the full internal state with a new state and notifies all registered Listener
        Parameters:
        state - the new state
      • addListener

        Subscription addListener(Listener<State> listener)
        Adds a new Listener to the store.

        The provided Listener will be notified on any state changes. If nothing else provided Filters.DEFAULT will be used to decide whether to notify or not.

        Parameters:
        listener - callback to be notified on state changes
        Returns:
        a subscription for managing the listener's lifecycle
      • addListener

        Subscription addListener(Filter<State> filter,
                                 Listener<State> listener)
        Adds a new Listener to the store.

        The provided Listener will be notified on any state changes. The provided Filter is used to decide whether to notify or not.

        Parameters:
        filter - function used to decide whether to notify or not
        listener - callback to be notified on state changes
        Returns:
        a subscription for managing the listener's lifecycle
      • addListener

        <E> Subscription addListener(StateSelector<E> stateSelector,
                                     Listener<E> listener)
        Adds a new Listener to the store.

        The provided Listener will be notified on any state changes. If the provided type E doesn't match the object behind the passed in key the listener will never be notified and a warning will be logged.
        If nothing else provided Filters.DEFAULT will be used to decide whether to notify or not.

        Type Parameters:
        E - type of the returned object of the state selector
        Parameters:
        stateSelector - function for converting State to an object of type <E>
        listener - callback to be notified on state changes
        Returns:
        a subscription for managing the listener's lifecycle
      • addListener

        <E> Subscription addListener(Filter<State> filter,
                                     StateSelector<E> stateSelector,
                                     Listener<E> listener)
        Adds a new Listener to the store.

        The provided Listener will be notified on any state changes. If the provided type E doesn't match the object behind the passed in key the listener will never be notified and a warning will be logged.
        If nothing else provided Filters.DEFAULT will be used to decide whether to notify or not.

        Type Parameters:
        E - type of the returned object of the state selector
        Parameters:
        filter - function used to decide whether to notify or not
        stateSelector - function for converting State to an object of type <E>
        listener - callback to be notified on state changes
        Returns:
        a subscription for managing the listener's lifecycle
      • addListener

        <E> Subscription addListener(java.lang.String stateKey,
                                     Listener<E> listener)
        Adds a new Listener to the store.

        The provided Listener will be notified on any changes to the part state that's tied to the passed in key. If the provided type E doesn't match the object behind the passed in key the listener will never be notified and a warning will be logged.
        If nothing else provided Filters.DEFAULT will be used to decide whether to notify or not.

        Type Parameters:
        E - type of the state that's registered on the provided key
        Parameters:
        stateKey - the state key to listen for changes
        listener - callback to be notified on state changes
        Returns:
        a subscription for managing the listener's lifecycle
      • addListener

        <E> Subscription addListener(java.lang.String stateKey,
                                     Filter<E> filter,
                                     Listener<E> listener)
        Adds a new Listener to the store.

        The provided Listener will be notified on any changes to the part state that's tied to the passed in key. If the provided type E doesn't match the object behind the passed in key the listener will never be notified and a warning will be logged.
        The provided Filter is used to decide whether to notify or not.

        Type Parameters:
        E - type of the state that's registered on the provided key
        Parameters:
        stateKey - the state key to listen for changes
        filter - function used to decide whether to notify or not
        listener - callback to be notified on state changes
        Returns:
        a subscription for managing the listener's lifecycle
      • addListener

        <E> Subscription addListener(java.lang.Class<E> clazz,
                                     Listener<E> listener)
        Adds a new Listener to the store.

        The provided Listener will be notified on any changes to the part state that's tied to the passed in Class. If the provided type E doesn't match the object behind the passed in class the listener will never be notified and a warning will be logged.
        If nothing else provided Filters.DEFAULT will be used to decide whether to notify or not.

        Type Parameters:
        E - type of the state that's registered on the provided key
        Parameters:
        clazz - the state key and type listen for changes
        listener - callback to be notified on state changes
        Returns:
        a subscription for managing the listener's lifecycle
      • addListener

        <E> Subscription addListener(java.lang.Class<E> clazz,
                                     Filter<E> filter,
                                     Listener<E> listener)
        Adds a new Listener to the store.

        The provided Listener will be notified on any changes to the part state that's tied to the passed in Class. If the provided type E doesn't match the object behind the passed in class the listener will never be notified and a warning will be logged.
        The provided Filter is used to decide whether to notify or not.

        Type Parameters:
        E - type of the state that's registered on the provided clazz
        Parameters:
        clazz - the state key and type to listen for changes
        filter - function used to decide whether to notify or not
        listener - callback to be notified on state changes
        Returns:
        a subscription for managing the listener's lifecycle
      • addListener

        <E> Subscription addListener(java.lang.String stateKey,
                                     java.lang.Class<E> clazz,
                                     Listener<E> listener)
        Adds a new Listener to the store.

        The provided Listener will be notified on any changes to the part state that's tied to the passed in key and of type clazz. If the provided type E doesn't match the object behind the passed in key the listener will never be notified and a warning will be logged.
        If nothing else provided Filters.DEFAULT will be used to decide whether to notify or not.

        Type Parameters:
        E - type of the state that's registered on the provided key
        Parameters:
        stateKey - the state key to listen for changes
        clazz - the state type to listen for changes
        listener - callback to be notified on state changes
        Returns:
        a subscription for managing the listener's lifecycle
      • addListener

        <E> Subscription addListener(java.lang.String stateKey,
                                     java.lang.Class<E> clazz,
                                     Filter<E> filter,
                                     Listener<E> listener)
        Adds a new Listener to the store.

        The provided Listener will be notified on any changes to the part state that's tied to the passed in key and of type clazz. If the provided type E doesn't match the object behind the passed in key the listener will never be notified and a warning will be logged.
        The provided Filter is used to decide whether to notify or not.

        Type Parameters:
        E - type of the state that's registered on the provided key
        Parameters:
        stateKey - the state key to listen for changes
        clazz - the state type to listen for changes
        filter - function used to decide whether to notify or not
        listener - callback to be notified on state changes
        Returns:
        a subscription for managing the listener's lifecycle
      • addActionListener

        Subscription addActionListener(Listener<Action<?>> actionListener)
        Adds a new Listener to the store.

        Action listeners will be notified whenever a new action is dispatched. Inside the action notification you cast to the specific action and read the payload of the action.

        Parameters:
        actionListener - callback to be notified when an action happens.
        Returns:
        a subscription for managing the listener's lifecycle
      • removeListener

        void removeListener(Listener<?> listener)
        Remove a listener from the store.
        Parameters:
        listener - the listener to remove