Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
spautz committed Sep 18, 2022
1 parent 7ec596c commit 6664bee
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -66,3 +66,5 @@ This may be used with a state library like Redux, or on its own as a general mem
hook</a>, you can specify your own comparison function to 'freeze' updates. This may be customized for each selector.
</dd>
</dl>

[**_Comparison between Reselect and Dyanamic Selectors_**](https://github.com/spautz/dynamic-selectors/blob/main/packages/core/docs/comparison-with-reselect.md)
31 changes: 30 additions & 1 deletion packages/core/README.md
Expand Up @@ -81,7 +81,7 @@ used if you call `getBookInfo(state, bookId)` directly.
</dd>
</dl>

[**Comparison between Reselect and Dyanamic Selectors**](https://github.com/spautz/dynamic-selectors/blob/main/packages/core/docs/comparison-with-reselect.md)
[**_Comparison between Reselect and Dyanamic Selectors_**](https://github.com/spautz/dynamic-selectors/blob/main/packages/core/docs/comparison-with-reselect.md)

## API

Expand Down Expand Up @@ -116,6 +116,35 @@ const getSortedList = createDynamicSelector((getState, { listId, sortField }) =>
getSortedList(state, { listId: 123, sortField: 'title' });
```

### Typings

In Typescript, the return type of the selector -- as well as any typings for its `params` or additional arguments --
will be inferred from the type of the function passed into it.

```typescript
const selector1 = createDynamicSelector(() => 3);
const value1 = selector1(); // type: number

const selector2 = createDynamicSelector(() => 'Hello');
const value2 = selector2(); // type: string

const selector3 = createDynamicSelector(
(getState, userId: number): UserModel => getState(['users', userId]),
);
const value3 = selector2(state, 123); // type: UserModel
const value4 = selector2(state, true); // error
```

Inside a selector, `getState` can be assigned a specific return type. (Default: `unknown`)

```typescript
createDynamicSelector((getState) => {
const value1 = getState<number>('path.to.number'); // type: number
const value2 = getState<boolean>('path.to.boolean', false); // type: boolean
const value3 = getState<string>('path.to.string', false); // error: defaultValue doesn't match string
});
```

### Additional selector properties

These are attached to the selector function returned by `createDynamicSelector`.
Expand Down
2 changes: 2 additions & 0 deletions packages/with-reselect/README.md
Expand Up @@ -3,6 +3,8 @@
Helper functions to make it easy to use [Dynamic Selectors](https://github.com/spautz/dynamic-selectors) and
[Reselect](https://github.com/reduxjs/reselect) together.

For more information or related packages, see the [Dynamic Selectors workspace](https://github.com/spautz/dynamic-selectors).

[![npm version](https://img.shields.io/npm/v/@dynamic-selectors/with-reselect.svg)](https://www.npmjs.com/package/@dynamic-selectors/with-reselect)
[![build status](https://github.com/spautz/dynamic-selectors/workflows/CI/badge.svg)](https://github.com/spautz/dynamic-selectors/actions)
[![test coverage](https://coveralls.io/repos/github/spautz/dynamic-selectors/badge.svg?branch=x-cov-with-reselect)](https://coveralls.io/github/spautz/dynamic-selectors?branch=x-cov-with-reselect)
Expand Down

0 comments on commit 6664bee

Please sign in to comment.