Objective Redux

Redux made better, objectively.

ComponentConnector

class ComponentConnector

Builder that connections a React component to the Objective Redux store, allowing the component to use the states and dispatch events.
This provides the React component with an `objectiveStore` prop, which is an instance of the ObjectiveStore connected to the components closest provided ancestor. It also provides props from the states that were added. As an alternative for functional components, the useObjectiveStore hook can be used to get the ObjectiveStore.

Examples

export default ComponentConnector
  .addPropsTo(MyReactComponent)
  .fromController(MyStateControllerOne)
  .fromController(MyStateControllerTwo, slice => ({ a: slice.a }))
  .connect();

connect

public connect(): any

Finishes the builder and provides the connected component.

Returns

any
The connected React component.

fromController

public fromController<StateType, C>(controller: Controller|ModelConstructor<StateController>, selector: StateSelectorFn<ReturnType>|null = null): ComponentConnector

Gets parameters from the specified StateController and injects them into the properties of the component.

Template Parameters

<StateType>

<C>
The state controller class being connected. Will be inferred from the first parameter.

Parameters

controller: Controller|ModelConstructor<StateController>
The state controller from which properties will be extracted.

selector: StateSelectorFn<ReturnType>|null = null
An optional mapping function.

Returns

ComponentConnector
An instance of the ComponentConnector builder.

fromState

public fromState(selectorFn: StateSelectorFn<any>): ComponentConnector

Adds a selection of the state to as props to the component.
This method is provided for backward compatibility purposes. For flexibility and performance reasons, it is encouraged that fromController method be used instead of this method when possible.

Parameters

selectorFn: StateSelectorFn<any>
A function that maps the state to a selected part of the state.

Returns

ComponentConnector
An instance of the ComponentConnector builder.

addPropsTo

public static addPropsTo(component: ComponentClass): ComponentConnector

Starts the builder for a React component.

Parameters

component: ComponentClass
The React component to which the props will be added.

Returns

ComponentConnector
An instance of the ComponentConnector builder.