Welcome to the ReduxPY documentation!

Implementation of a Redux store with support for adding feature modules, dynamically. The store exposes a reactive API based on RxPY.

class redux.Action(type: str, payload: Any)

Action implementation that takes a payload

payload: Any

The action action payload

type: str

Identifier for the action, must be globally unique.

redux.Epic

The central part of internal API.

This represents a generic version of type ‘origin’ with type arguments ‘params’. There are two kind of these aliases: user defined and special. The special ones are wrappers around builtin collections and ABCs in collections.abc. These must have ‘name’ always set. If ‘inst’ is False, then the alias can’t be instantiated, this is used by e.g. typing.List and typing.Dict.

alias of Callable[[rx.core.observable.observable.Observable, rx.core.observable.observable.Observable], rx.core.observable.observable.Observable]

redux.Reducer

The central part of internal API.

This represents a generic version of type ‘origin’ with type arguments ‘params’. There are two kind of these aliases: user defined and special. The special ones are wrappers around builtin collections and ABCs in collections.abc. These must have ‘name’ always set. If ‘inst’ is False, then the alias can’t be instantiated, this is used by e.g. typing.List and typing.Dict.

alias of Callable[[StateType, redux._internal.types.Action], StateType]

class redux.ReduxFeatureModule(id: str, reducer: Optional[Callable[[StateType, redux._internal.types.Action], StateType]], epic: Optional[Callable[[rx.core.observable.observable.Observable, rx.core.observable.observable.Observable], rx.core.observable.observable.Observable]], dependencies: Iterable[ReduxFeatureModule])

Defines the feature module. The ID identifies the section in the state and is also used to globally discriminate features.

After instantiating a feature store the store will fire an initialization action for that feature. Use of_init_feature() to register for these initialization actions.

dependencies: Iterable[redux._internal.types.ReduxFeatureModule]

Dependencies on other feature modules

epic: Optional[Callable[[rx.core.observable.observable.Observable, rx.core.observable.observable.Observable], rx.core.observable.observable.Observable]]

Epic that handles module specific asynchronous operations.

id: str

Identifier of the module, will also be used as a namespace into the state.

reducer: Optional[Callable[[StateType, redux._internal.types.Action], StateType]]

Reducer that handles module specific actions.

class redux.ReduxRootStore(as_observable: Callable[], rx.core.observable.observable.Observable], dispatch: Callable[[redux._internal.types.Action], None], add_feature_module: Callable[[redux._internal.types.ReduxFeatureModule], None], on_next: Callable[[redux._internal.types.Action], None], on_completed: Callable[], None])

Implementation of a store that manages sub-state as features. Features are added to the store automatically, when required by the select method.

add_feature_module: Callable[[redux._internal.types.ReduxFeatureModule], None]

Adds a new feature module

as_observable: Callable[], rx.core.observable.observable.Observable]

Converts the store to an observable of state emissions

dispatch: Callable[[redux._internal.types.Action], None]

Dispatches a single action to the store

on_completed: Callable[], None]

Shuts down the store

on_next: Callable[[redux._internal.types.Action], None]

Alias for dispatch()

redux.combine_epics(*epics)

Combines a sequence of epics into one single epic by merging them

Parameters

epics (Iterable[Callable[[Observable, Observable], Observable]]) – the epics to merge

Return type

Callable[[Observable, Observable], Observable]

Returns

The merged epic

redux.combine_reducers(reducers)

Creates a new reducer from a mapping of reducers.

Parameters

reducers (Mapping[str, Callable[[~StateType, Action], ~StateType]]) – the mapping from state partition to reducer

Return type

Callable[[Mapping[str, ~StateType], Action], Mapping[str, ~StateType]]

Returns

A reducer that dispatches actions against each of the mapped reducers

redux.create_action(type_name)

Creates a function that produces an action of the given type

Parameters

type_name (str) – type of the action

Return type

Callable[[~PayloadType], Action]

Returns

A function that accepts the action payload and creates the action

redux.create_feature_module(identifier, reducer=None, epic=None, dependencies=())

Constructs a new feature module descriptor

Parameters
  • identifier (str) – the identifier of the feature

  • reducer (Optional[Callable[[~StateType, Action], ~StateType]]) – optional reducer

  • epic (Optional[Callable[[Observable, Observable], Observable]]) – optional epic

  • dependencies (Iterable[ReduxFeatureModule]) – optional dependencies on other features

Return type

ReduxFeatureModule

Returns

The feature module descriptor

redux.create_store(initial_state=None)

Constructs a new store that can handle feature modules.

Parameters

initial_state (Optional[Mapping[str, ~StateType]]) – optional initial state of the store, will typically be the empty dict

Return type

ReduxRootStore

Returns

An implementation of the store

redux.handle_actions(action_map, initial_state=None)

Creates a new reducer from a mapping of action name to reducer for that action.

Parameters
  • action_map (Mapping[str, Callable[[~StateType, Action], ~StateType]]) – mapping from action name to reducer for that action

  • initial_state (Optional[~StateType]) – optional initial state used if no reducer matches

Return type

Callable[[~StateType, Action], ~StateType]

Returns

A reducer function that handles the actions in the map

redux.of_init_feature(identifier)

Operator to test for the initialization action of a feature

Parameters

identifier (str) – the identifier of the feature

Return type

Callable[[Observable], Observable]

Returns

Operator function that accepts init actions for the feature, once

redux.of_type(type_name)

Returns a reactive operator that filters for actions of the given type

Parameters

type_name (str) – type of the action to filter for

Return type

Callable[[Observable], Observable]

Returns

The filter operator function

redux.select(selector)

Reactive operator that applies a selector and shares the result across multiple subscribers

Parameters

selector (Callable[[~T1], ~T2]) – the selector function

Return type

Callable[[Observable], Observable]

Returns

The reactive operator

redux.select_action_payload(action)

Selects the payload from the action

Parameters

action (Action) – the action object

Return type

~PayloadType

Returns

the payload of the action

redux.select_feature(identifier, initial_state=None)

Returns a function that returns the feature state from the root state

Parameters
  • identifier (str) – identifier of the feature

  • initial_state (Optional[~StateType]) – fallback state used if the feature state is not defined

Return type

Callable[[Mapping[str, ~StateType]], Optional[~StateType]]

Returns

The selector function