Skip to content

Commit

Permalink
feat(selectors): curry selectStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
Pixeladed committed Oct 20, 2020
1 parent 983d8af commit 3f59dc6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ adapter.resetAllStatuses(state);
adapter.getSelectors().selectData(state);
```

- `selectStatus`: accepts an `asyncThunk` (created by redux toolkit's `createAsyncThunk`) and the state and returns the status object of that particular thunk
- `selectStatus`: accepts an `asyncThunk` (created by redux toolkit's `createAsyncThunk`) and returns a selector that accepts a state and returns the status object of that particular thunk

```typescript
adapter.getSelectors().selectStatus(state, thunk);
adapter.getSelectors().selectStatus(thunk)(state);
```

- `selectAllStatuses`: returns an array of all status objects within the state
Expand Down
3 changes: 1 addition & 2 deletions src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ export const selectData = <Data>(state: AsyncState<Data>) => {
* @param asyncThunk the async thunk created by createAsyncThunk
*/
export const selectStatus = <Data, Returned, ThunkArg, ThunkApiConfig>(
state: AsyncState<Data>,
asyncThunk: AsyncThunk<Returned, ThunkArg, ThunkApiConfig>
) => {
) => (state: AsyncState<Data>) => {
const status =
state.status[asyncThunk.typePrefix] ||
getDefaultStatus(asyncThunk.typePrefix);
Expand Down
4 changes: 2 additions & 2 deletions test/selectors/selectStatus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('selectStatus', () => {
reducer: () => adapter.getInitialState({}),
});

const status = adapter.getSelectors().selectStatus(store.getState(), thunk);
const status = adapter.getSelectors().selectStatus(thunk)(store.getState());
expect(status).toEqual(getDefaultStatus(thunk.typePrefix));
});

Expand All @@ -34,7 +34,7 @@ describe('selectStatus', () => {
store.dispatch(thunk());
await flushPromises();

const status = adapter.getSelectors().selectStatus(store.getState(), thunk);
const status = adapter.getSelectors().selectStatus(thunk)(store.getState());
const result: Partial<AsyncStatus> = {
name: thunk.typePrefix,
error: undefined,
Expand Down

0 comments on commit 3f59dc6

Please sign in to comment.