Skip to content

Commit

Permalink
refactor: split redux.ts in multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
x8lucas8x committed Dec 13, 2019
1 parent 3a70c10 commit 27abbb0
Show file tree
Hide file tree
Showing 12 changed files with 286 additions and 241 deletions.
72 changes: 51 additions & 21 deletions docs/docs/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ generated from source.

# react-resux


## Index

### Classes
Expand All @@ -38,16 +37,17 @@ generated from source.

### Redux/Saga Setup Functions

* [bindResuxActionCreators](README.md#bindresuxactioncreators)
* [combineModelReducers](README.md#combinemodelreducers)
* [resuxRootSaga](README.md#resuxrootsaga)

## High Order Component (HOC) Functions

### connectResux

**connectResux**(`modelsOrSubscribers`: [Model](classes/model.md) | [Subscriber](classes/subscriber.md)[], `userProvidedMapStateToProps`: MapStateToPropsWithSelectors‹any, any, any›, `userProvidedMapDispatchToProps`: MapDispatchToPropsWithActionCreators‹any, any›): *any*
**connectResux**(`modelsOrSubscribers`: [Model](classes/model.md)‹› | [Subscriber](classes/subscriber.md)‹›[], `userProvidedMapStateToProps`: MapStateToPropsWithSelectors‹any, any, any›, `userProvidedMapDispatchToProps`: MapDispatchToPropsWithActionCreators‹any, any›): *any*

*Defined in [react-resux/src/redux.ts:84](https://github.com/kayak/kaytum/blob/164e3a8/packages/react-resux/src/redux.ts#L84)*
*Defined in [react-resux/src/redux/connectResux.ts:22](https://github.com/kayak/kaytum/blob/f60c566/packages/react-resux/src/redux/connectResux.ts#L22)*

Equivalent to redux's connect function. This should be used when the hooks api is not desired or
supported. Otherwise check [useModelActions](README.md#usemodelactions), [useModelSelector](README.md#usemodelselector), and [useSubscriberActions](README.md#usesubscriberactions) up.
Expand All @@ -59,7 +59,7 @@ const ConnectedComponent = connectResux([modelA, modelB], mapStateToProps, mapDi

Name | Type | Default | Description |
------ | ------ | ------ | ------ |
`modelsOrSubscribers` | [Model](classes/model.md) | [Subscriber](classes/subscriber.md)[] | - | An array of either Model or Subscriber instances. |
`modelsOrSubscribers` | [Model](classes/model.md)‹› | [Subscriber](classes/subscriber.md)‹›[] | - | An array of either Model or Subscriber instances. |
`userProvidedMapStateToProps` | MapStateToPropsWithSelectors‹any, any, any› | null | A mapToProps equivalent, which has a third argument with all selectors. |
`userProvidedMapDispatchToProps` | MapDispatchToPropsWithActionCreators‹any, any› | null | A mapDispatchToProps equivalent, which has a third argument with all models' action creators and a fourth argument with all subscriber's action creators. |

Expand All @@ -73,9 +73,9 @@ ___

### useModelActions

**useModelActions**(`model`: [Model](classes/model.md)): *ActionCreatorsMapObject*
**useModelActions**(`model`: [Model](classes/model.md)): *BoundActionCreatorsMapObject*

*Defined in [react-resux-hooks/src/useModelActions.ts:17](https://github.com/kayak/kaytum/blob/164e3a8/packages/react-resux-hooks/src/useModelActions.ts#L17)*
*Defined in [react-resux-hooks/src/useModelActions.ts:19](https://github.com/kayak/kaytum/blob/f60c566/packages/react-resux-hooks/src/useModelActions.ts#L19)*

A react hook for returning already bound action creators for the provided model. If you don't want/need to use
the hooks api, check [connectResux](README.md#connectresux) up.
Expand All @@ -89,17 +89,19 @@ Name | Type | Description |
------ | ------ | ------ |
`model` | [Model](classes/model.md) | A model instance. |

**Returns:** *ActionCreatorsMapObject*
**Returns:** *BoundActionCreatorsMapObject*

An object with already bound action creators.
An object with already bound action creators. The bound action creators return a promise when invoked,
which can be used to track if the action was properly processed (i.e. resolved) or caused an exception
(i.e. rejected).

___

### useModelSelector

**useModelSelector**(`model`: [Model](classes/model.md), `selectorFunc`: any): *Record‹string, function›*
**useModelSelector**(`model`: [Model](classes/model.md), `selectorFunc`: SelectorFunction): *any*

*Defined in [react-resux-hooks/src/useModelSelector.ts:16](https://github.com/kayak/kaytum/blob/164e3a8/packages/react-resux-hooks/src/useModelSelector.ts#L16)*
*Defined in [react-resux-hooks/src/useModelSelector.ts:19](https://github.com/kayak/kaytum/blob/f60c566/packages/react-resux-hooks/src/useModelSelector.ts#L19)*

A react hook for returning data from the provided model's state, by the means of one of its selectors. If you
don't want/need to use the hooks api, check [connectResux](README.md#connectresux) up.
Expand All @@ -112,19 +114,19 @@ const someDataFromState = useModelSelector(model, (state, selectors) => selector
Name | Type | Description |
------ | ------ | ------ |
`model` | [Model](classes/model.md) | A model instance. |
`selectorFunc` | any | - |
`selectorFunc` | SelectorFunction | A selector func, which will call one of the selectors in the provided model. The first argument must be the entire redux state, followed by the selectors map of the model. |

**Returns:** *Record‹string, function›*
**Returns:** *any*

Data from model's state.

___

### useSubscriberActions

**useSubscriberActions**(`subscriber`: [Subscriber](classes/subscriber.md)): *ActionCreatorsMapObject*
**useSubscriberActions**(`subscriber`: [Subscriber](classes/subscriber.md)): *BoundActionCreatorsMapObject*

*Defined in [react-resux-hooks/src/useSubscriberActions.ts:17](https://github.com/kayak/kaytum/blob/164e3a8/packages/react-resux-hooks/src/useSubscriberActions.ts#L17)*
*Defined in [react-resux-hooks/src/useSubscriberActions.ts:19](https://github.com/kayak/kaytum/blob/f60c566/packages/react-resux-hooks/src/useSubscriberActions.ts#L19)*

A react hook for returning already bound action creators for the provided subscriber. If you don't want/need
to use the hooks api, check [connectResux](README.md#connectresux) up.
Expand All @@ -138,19 +140,47 @@ Name | Type | Description |
------ | ------ | ------ |
`subscriber` | [Subscriber](classes/subscriber.md) | A subscriber instance. |

**Returns:** *ActionCreatorsMapObject*
**Returns:** *BoundActionCreatorsMapObject*

An object with already bound action creators.
An object with already bound action creators. The bound action creators return a promise when invoked,
which can be used to track if the action was properly processed (i.e. resolved) or caused an exception
(i.e. rejected).

___

## Redux/Saga Setup Functions

### bindResuxActionCreators

**bindResuxActionCreators**(`actionCreators`: ActionCreatorsMapObject, `dispatch`: Dispatch): *BoundNamespacedActionCreatorsMapObject*

*Defined in [react-resux/src/redux/bindResuxActionCreators.ts:24](https://github.com/kayak/kaytum/blob/f60c566/packages/react-resux/src/redux/bindResuxActionCreators.ts#L24)*

Turns an object whose values are action creators or nested objects with them, into an object with the
same keys, but with every action creator wrapped into a dispatch call so they may be invoked directly.
A Promise will be returned on every invocation, which can be used to track if the action was properly
processed (i.e. resolved) or caused an exception (i.e. rejected).

**Parameters:**

Name | Type | Description |
------ | ------ | ------ |
`actionCreators` | ActionCreatorsMapObject | a namespaced action creator's map object. This can have multiple levels of nesting, depending on the namespaces of the models involved. |
`dispatch` | Dispatch | A dispatch function available on the Store instance.. |

**Returns:** *BoundNamespacedActionCreatorsMapObject*

An object mimicking the original object, but with each function immediately dispatching the
action returned by the corresponding action creator. And returning a Promise, which will resolve/
reject once done.

___

### combineModelReducers

**combineModelReducers**(`models`: [Model](classes/model.md)[]): *ReducersMapObject*

*Defined in [react-resux/src/redux.ts:110](https://github.com/kayak/kaytum/blob/164e3a8/packages/react-resux/src/redux.ts#L110)*
*Defined in [react-resux/src/redux/combineModelReducers.ts:34](https://github.com/kayak/kaytum/blob/f60c566/packages/react-resux/src/redux/combineModelReducers.ts#L34)*

Returns a reducer map object that can be deconstructed into the combineReducers helper, from redux, so that
redux is aware of any reducers produced by models.
Expand All @@ -176,9 +206,9 @@ ___

### resuxRootSaga

**resuxRootSaga**(`sagaContainers`: [Model](classes/model.md) | [Subscriber](classes/subscriber.md)[]): *SagaIterator*
**resuxRootSaga**(`sagaContainers`: [Model](classes/model.md)‹› | [Subscriber](classes/subscriber.md)‹›[]): *SagaIterator*

*Defined in [react-resux/src/redux.ts:140](https://github.com/kayak/kaytum/blob/164e3a8/packages/react-resux/src/redux.ts#L140)*
*Defined in [react-resux/src/saga.ts:55](https://github.com/kayak/kaytum/blob/f60c566/packages/react-resux/src/saga.ts#L55)*

Returns a root saga generator that can be passed to sagaMiddleware's run function, so that redux-saga is aware
of any sagas produced by either models or subscribers.
Expand All @@ -190,8 +220,8 @@ sagaMiddleware.run(() => resuxRootSaga([modelA, subscriberA]));

Name | Type | Description |
------ | ------ | ------ |
`sagaContainers` | [Model](classes/model.md) | [Subscriber](classes/subscriber.md)[] | An array of either Model or Subscriber instances. |
`sagaContainers` | [Model](classes/model.md)‹› | [Subscriber](classes/subscriber.md)‹›[] | An array of either Model or Subscriber instances. |

**Returns:** *SagaIterator*

A root saga.
A root saga.
21 changes: 11 additions & 10 deletions docs/docs/api/classes/model.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ generated from source.

# Class: Model


Models are the most basic data structure/abstraction in this library. They require a set of options to be
provided when initializing them. The model will be used to generate the action types, actions, reducers,
dispatchers, and sagas, based on the model's options that were provided.
Expand Down Expand Up @@ -48,7 +47,7 @@ dispatchers, and sagas, based on the model's options that were provided.

\+ **new Model**(`options`: [ModelOptions](../interfaces/modeloptions.md)): *[Model](model.md)*

*Defined in [react-resux/src/model.ts:161](https://github.com/kayak/kaytum/blob/164e3a8/packages/react-resux/src/model.ts#L161)*
*Defined in [react-resux/src/model.ts:193](https://github.com/kayak/kaytum/blob/f60c566/packages/react-resux/src/model.ts#L193)*

Creates a model instance.

Expand Down Expand Up @@ -92,7 +91,7 @@ Name | Type | Description |

**get effects**(): *EffectMap*

*Defined in [react-resux/src/model.ts:376](https://github.com/kayak/kaytum/blob/164e3a8/packages/react-resux/src/model.ts#L376)*
*Defined in [react-resux/src/model.ts:426](https://github.com/kayak/kaytum/blob/f60c566/packages/react-resux/src/model.ts#L426)*

Returns the effects.

Expand All @@ -106,7 +105,7 @@ ___

**get namespace**(): *string*

*Defined in [react-resux/src/model.ts:340](https://github.com/kayak/kaytum/blob/164e3a8/packages/react-resux/src/model.ts#L340)*
*Defined in [react-resux/src/model.ts:390](https://github.com/kayak/kaytum/blob/f60c566/packages/react-resux/src/model.ts#L390)*

Returns the namespace.

Expand All @@ -120,7 +119,7 @@ ___

**get reducers**(): *ReducerMap*

*Defined in [react-resux/src/model.ts:367](https://github.com/kayak/kaytum/blob/164e3a8/packages/react-resux/src/model.ts#L367)*
*Defined in [react-resux/src/model.ts:417](https://github.com/kayak/kaytum/blob/f60c566/packages/react-resux/src/model.ts#L417)*

Returns the reducers.

Expand All @@ -134,12 +133,14 @@ ___

**get reduxSagas**(): *Saga[]*

*Defined in [react-resux/src/model.ts:322](https://github.com/kayak/kaytum/blob/164e3a8/packages/react-resux/src/model.ts#L322)*
*Defined in [react-resux/src/model.ts:374](https://github.com/kayak/kaytum/blob/f60c566/packages/react-resux/src/model.ts#L374)*

Returns an array of sagas, one for each of the declared effects. They will default to taking every action and
calling its respective effect. For taking only latest or leading actions, at any given moment, look for
subscribers instead.

**`throws`** {NonCompatibleActionError} When bindResuxActionCreators was not used to bind the action creators.

**Returns:** *Saga[]*

An array of sagas.
Expand All @@ -150,7 +151,7 @@ ___

**get selectors**(): *SelectorMap*

*Defined in [react-resux/src/model.ts:358](https://github.com/kayak/kaytum/blob/164e3a8/packages/react-resux/src/model.ts#L358)*
*Defined in [react-resux/src/model.ts:408](https://github.com/kayak/kaytum/blob/f60c566/packages/react-resux/src/model.ts#L408)*

Returns the selectors.

Expand All @@ -164,7 +165,7 @@ ___

**get state**(): *State*

*Defined in [react-resux/src/model.ts:349](https://github.com/kayak/kaytum/blob/164e3a8/packages/react-resux/src/model.ts#L349)*
*Defined in [react-resux/src/model.ts:399](https://github.com/kayak/kaytum/blob/f60c566/packages/react-resux/src/model.ts#L399)*

Returns the initial state.

Expand All @@ -178,12 +179,12 @@ An initial state.

**actionCreators**(): *ActionCreatorsMapObject*

*Defined in [react-resux/src/model.ts:256](https://github.com/kayak/kaytum/blob/164e3a8/packages/react-resux/src/model.ts#L256)*
*Defined in [react-resux/src/model.ts:298](https://github.com/kayak/kaytum/blob/f60c566/packages/react-resux/src/model.ts#L298)*

Returns an object with action creators, one for each of the declared reducers and effects. Only useful for
testing purposes, read the docs section on testing for more info. Also supports the inner workings of this
class.

**Returns:** *ActionCreatorsMapObject*

an action creator's map object.
an action creator's map object.
19 changes: 9 additions & 10 deletions docs/docs/api/classes/subscriber.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ generated from source.

# Class: Subscriber


Subscribers provide a way to link models' effects/reducers, so that they get triggered by the same non-namespaced
action type, on a leading, latest, or every action basis. That is, they provide the means for generating redux
sagas employing takeLeading, takeLatest, or takeEvery effects.
Expand Down Expand Up @@ -51,7 +50,7 @@ sagas employing takeLeading, takeLatest, or takeEvery effects.

\+ **new Subscriber**(`models`: [Model](model.md)[]): *[Subscriber](subscriber.md)*

*Defined in [react-resux/src/subscriber.ts:14](https://github.com/kayak/kaytum/blob/164e3a8/packages/react-resux/src/subscriber.ts#L14)*
*Defined in [react-resux/src/subscriber.ts:15](https://github.com/kayak/kaytum/blob/f60c566/packages/react-resux/src/subscriber.ts#L15)*

Creates a subscriber instance.

Expand All @@ -69,23 +68,23 @@ Name | Type | Description |

**effectNames**: *string[]*

*Defined in [react-resux/src/subscriber.ts:13](https://github.com/kayak/kaytum/blob/164e3a8/packages/react-resux/src/subscriber.ts#L13)*
*Defined in [react-resux/src/subscriber.ts:14](https://github.com/kayak/kaytum/blob/f60c566/packages/react-resux/src/subscriber.ts#L14)*

___

### models

**models**: *[Model](model.md)[]*

*Defined in [react-resux/src/subscriber.ts:12](https://github.com/kayak/kaytum/blob/164e3a8/packages/react-resux/src/subscriber.ts#L12)*
*Defined in [react-resux/src/subscriber.ts:13](https://github.com/kayak/kaytum/blob/f60c566/packages/react-resux/src/subscriber.ts#L13)*

## Accessors

### reduxSagas

**get reduxSagas**(): *Saga[]*

*Defined in [react-resux/src/subscriber.ts:128](https://github.com/kayak/kaytum/blob/164e3a8/packages/react-resux/src/subscriber.ts#L128)*
*Defined in [react-resux/src/subscriber.ts:127](https://github.com/kayak/kaytum/blob/f60c566/packages/react-resux/src/subscriber.ts#L127)*

Returns an array of sagas, one for each of the declared effects.

Expand All @@ -99,7 +98,7 @@ An array of sagas.

**actionCreators**(): *ActionCreatorsMapObject*

*Defined in [react-resux/src/subscriber.ts:38](https://github.com/kayak/kaytum/blob/164e3a8/packages/react-resux/src/subscriber.ts#L38)*
*Defined in [react-resux/src/subscriber.ts:39](https://github.com/kayak/kaytum/blob/f60c566/packages/react-resux/src/subscriber.ts#L39)*

Returns an object with action creators, one for each of the declared effects. Only useful for testing purposes,
read the docs section on testing for more info. Also supports the inner workings of this class.
Expand All @@ -114,7 +113,7 @@ ___

**takeEvery**(`actionType`: string, `actionGenerators`: any): *[Subscriber](subscriber.md)*

*Defined in [react-resux/src/subscriber.ts:119](https://github.com/kayak/kaytum/blob/164e3a8/packages/react-resux/src/subscriber.ts#L119)*
*Defined in [react-resux/src/subscriber.ts:118](https://github.com/kayak/kaytum/blob/f60c566/packages/react-resux/src/subscriber.ts#L118)*

Adds a subscription, which will watch for the provided actionType. It will default to taking every action and
calling the respective action generator, which is equivalent to the behaviour of effects declared in models.
Expand All @@ -137,7 +136,7 @@ ___

**takeLatest**(`actionType`: string, `actionGenerators`: any): *[Subscriber](subscriber.md)*

*Defined in [react-resux/src/subscriber.ts:92](https://github.com/kayak/kaytum/blob/164e3a8/packages/react-resux/src/subscriber.ts#L92)*
*Defined in [react-resux/src/subscriber.ts:91](https://github.com/kayak/kaytum/blob/f60c566/packages/react-resux/src/subscriber.ts#L91)*

Adds a subscription, which will watch for the provided actionType. It will default to taking only the latest
action at any given moment and calling the respective action generator. This is useful for implementing
Expand All @@ -161,7 +160,7 @@ ___

**takeLeading**(`actionType`: string, `actionGenerators`: any): *[Subscriber](subscriber.md)*

*Defined in [react-resux/src/subscriber.ts:106](https://github.com/kayak/kaytum/blob/164e3a8/packages/react-resux/src/subscriber.ts#L106)*
*Defined in [react-resux/src/subscriber.ts:105](https://github.com/kayak/kaytum/blob/f60c566/packages/react-resux/src/subscriber.ts#L105)*

Adds a subscription, which will watch for the provided actionType. It will default to taking only the leading
action at any given moment and calling the respective action generator. This is useful for implementing
Expand All @@ -177,4 +176,4 @@ Name | Type | Description |

**Returns:** *[Subscriber](subscriber.md)*

this.
this.
Loading

0 comments on commit 27abbb0

Please sign in to comment.