Skip to content

Commit

Permalink
Merge pull request #3 from SIARHEI-SMANTSAR/develop
Browse files Browse the repository at this point in the history
feat: add support typesafe-actions
  • Loading branch information
SIARHEI-SMANTSAR authored May 7, 2020
2 parents c8604ba + 6290fa4 commit 9795874
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 8 deletions.
91 changes: 85 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,21 @@ npm install redux-requests-factory --save
- [Global Selectors](#global-selectors)
- [`isSomethingLoadingSelector`](#issomethingloadingselector)
- [Create Redux Requests Factory](#create-redux-requests-factory)
- [SSR](#ssr)
- [TypeScript](#typescript)
- [License](#license)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Examples

[All examples](https://github.com/SIARHEI-SMANTSAR/redux-requests-factory/tree/develop/examples)
[All examples](https://github.com/SIARHEI-SMANTSAR/redux-requests-factory/tree/master/examples)

[create-react-app](https://github.com/SIARHEI-SMANTSAR/redux-requests-factory/tree/develop/examples/create-react-app)
[create-react-app](https://github.com/SIARHEI-SMANTSAR/redux-requests-factory/tree/master/examples/create-react-app)

[next.js](https://github.com/SIARHEI-SMANTSAR/redux-requests-factory/tree/develop/examples/next-js)
[next.js](https://github.com/SIARHEI-SMANTSAR/redux-requests-factory/tree/master/examples/next-js)

[redux-observabl](https://github.com/SIARHEI-SMANTSAR/redux-requests-factory/tree/develop/examples/create-react-app/with-redux-observable)
[redux-observabl](https://github.com/SIARHEI-SMANTSAR/redux-requests-factory/tree/master/examples/create-react-app/with-redux-observable)

## Installation

Expand Down Expand Up @@ -512,6 +513,25 @@ const {...} = requestsFactory({
const {...} = requestsFactory({
stateRequestKey: 'user-posts',
});

// Now the state is like here
// state = {
// [stateRequestsKey]: {
// responses: {
// users: {
// status: RequestsStatuses.None,
// response: undefined,
// error: undefined,
// },
// 'user-posts': {
// status: RequestsStatuses.None,
// response: undefined,
// error: undefined,
// },
// },
// },
// };

```

### Serialize
Expand Down Expand Up @@ -565,6 +585,36 @@ errorSelector(store)({ id: 1 });
requestStatusSelector(store)({ id: 1 });
isLoadingSelector(store)({ id: 1 });
isLoadedSelector(store)({ id: 1 });


// loadDataAction({ id: 1 });
// loadDataAction({ id: 2 });
// loadDataAction({ id: 3 });
//
// Now the state is like here
// state = {
// [stateRequestsKey]: {
// responses: {
// user: {
// '1': {
// status: RequestsStatuses.Loading,
// response: undefined,
// error: undefined,
// },
// '2': {
// status: RequestsStatuses.Loading,
// response: undefined,
// error: undefined,
// },
// '3': {
// status: RequestsStatuses.Loading,
// response: undefined,
// error: undefined,
// },
// },
// },
// },
// };
```

### Debounce
Expand Down Expand Up @@ -1037,13 +1087,42 @@ export const {
});
```

## SSR

`store.js`

```js
const makeStore = (initialState) => {
const { middleware, toPromise } = createRequestsFactoryMiddleware();
const reduxMiddleware = applyMiddleware(middleware);

const store = createStore(reducer, initialState, reduxMiddleware);

store.asyncRequests = toPromise;

return store;
};
```

`app.js`

```js
const loadData = async ({ isServer, store }) => {
store.dispatch(loadUsersAction());

if (isServer) {
await store.asyncRequests();
}
}
```

## TypeScript

Full support TypeScript

[TypeScript + create-react-app + redux-requests-factory](https://github.com/SIARHEI-SMANTSAR/redux-requests-factory/tree/develop/examples/create-react-app)
[TypeScript + create-react-app + redux-requests-factory](https://github.com/SIARHEI-SMANTSAR/redux-requests-factory/tree/master/examples/create-react-app)

[TypeScript + next.js + redux-requests-factory](https://github.com/SIARHEI-SMANTSAR/redux-requests-factory/tree/develop/examples/next-js)
[TypeScript + next.js + redux-requests-factory](https://github.com/SIARHEI-SMANTSAR/redux-requests-factory/tree/master/examples/next-js)

## License

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "redux-requests-factory",
"version": "1.0.0",
"version": "1.0.1",
"description": "Redux requests factory",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
2 changes: 2 additions & 0 deletions src/factory/create-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const createActions = <

syncAction.type = type;
syncAction.toString = () => type;
syncAction.getType = () => type;

return syncAction;
};
Expand Down Expand Up @@ -173,6 +174,7 @@ const createActions = <

asyncAction.type = type;
asyncAction.toString = () => type;
asyncAction.getType = () => type;

return asyncAction;
};
Expand Down
1 change: 1 addition & 0 deletions src/types/factory/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export enum FactoryActionTypes {
export interface RequestFactoryActionCommon {
type: string;
toString(): string;
getType(): string;
}

export interface RequestFactoryActionCommonWithSerializeReturnType {
Expand Down

0 comments on commit 9795874

Please sign in to comment.