Skip to content

Commit

Permalink
docs(api): update api docs
Browse files Browse the repository at this point in the history
  • Loading branch information
unadlib committed Jan 31, 2023
1 parent 557d56b commit 2ef61ce
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 40 deletions.
46 changes: 19 additions & 27 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ mutative

#### Defined in

[interface.ts:149](/~https://github.com/unadlib/mutative/blob/66089ec/src/interface.ts#L149)
[interface.ts:167](/~https://github.com/unadlib/mutative/blob/557d56b/src/interface.ts#L167)

___

Expand All @@ -58,31 +58,23 @@ ___

#### Defined in

[interface.ts:131](/~https://github.com/unadlib/mutative/blob/66089ec/src/interface.ts#L131)
[interface.ts:149](/~https://github.com/unadlib/mutative/blob/557d56b/src/interface.ts#L149)

___

### Patch

Ƭ **Patch**<`P`\>: `Object`
Ƭ **Patch**<`P`\>: `P` extends { `pathAsArray`: ``false`` } ? `IPatch` & { `path`: `string` } : `P` extends ``true`` \| `object` ? `IPatch` & { `path`: (`string` \| `number`)[] } : `IPatch` & { `path`: `string` \| (`string` \| `number`)[] }

#### Type parameters

| Name | Type |
| :------ | :------ |
| `P` | extends `PatchesOptions` |

#### Type declaration

| Name | Type |
| :------ | :------ |
| `op` | typeof `Operation`[keyof typeof `Operation`] |
| `path` | `P` extends { `pathAsArray`: ``false`` } ? `string` : (`string` \| `number`)[] |
| `value?` | `any` |
| `P` | extends `PatchesOptions` = `any` |

#### Defined in

[interface.ts:53](/~https://github.com/unadlib/mutative/blob/66089ec/src/interface.ts#L53)
[interface.ts:63](/~https://github.com/unadlib/mutative/blob/557d56b/src/interface.ts#L63)

___

Expand All @@ -98,7 +90,7 @@ ___

#### Defined in

[interface.ts:59](/~https://github.com/unadlib/mutative/blob/66089ec/src/interface.ts#L59)
[interface.ts:77](/~https://github.com/unadlib/mutative/blob/557d56b/src/interface.ts#L77)

## Functions

Expand Down Expand Up @@ -147,7 +139,7 @@ expect(state).toEqual(apply(baseState, patches));

#### Defined in

[apply.ts:26](/~https://github.com/unadlib/mutative/blob/66089ec/src/apply.ts#L26)
[apply.ts:26](/~https://github.com/unadlib/mutative/blob/557d56b/src/apply.ts#L26)

___

Expand Down Expand Up @@ -175,7 +167,7 @@ Cast a value to an Draft type value.

#### Defined in

[utils/cast.ts:6](/~https://github.com/unadlib/mutative/blob/66089ec/src/utils/cast.ts#L6)
[utils/cast.ts:7](/~https://github.com/unadlib/mutative/blob/557d56b/src/utils/cast.ts#L7)

___

Expand Down Expand Up @@ -203,7 +195,7 @@ Cast a value to an Immutable type value.

#### Defined in

[utils/cast.ts:13](/~https://github.com/unadlib/mutative/blob/66089ec/src/utils/cast.ts#L13)
[utils/cast.ts:14](/~https://github.com/unadlib/mutative/blob/557d56b/src/utils/cast.ts#L14)

___

Expand Down Expand Up @@ -255,7 +247,7 @@ expect(state.arr).toBe(baseState.arr);

#### Defined in

[create.ts:35](/~https://github.com/unadlib/mutative/blob/66089ec/src/create.ts#L35)
[create.ts:41](/~https://github.com/unadlib/mutative/blob/557d56b/src/create.ts#L41)

**create**<`T`, `F`, `O`, `R`\>(`base`, `mutate`, `options?`): `CreateResult`<`T`, `O`, `F`, `R`\>

Expand All @@ -282,7 +274,7 @@ expect(state.arr).toBe(baseState.arr);

#### Defined in

[create.ts:45](/~https://github.com/unadlib/mutative/blob/66089ec/src/create.ts#L45)
[create.ts:51](/~https://github.com/unadlib/mutative/blob/557d56b/src/create.ts#L51)

**create**<`T`, `P`, `F`, `O`, `R`\>(`mutate`, `options?`): (`base`: `T`, ...`args`: `P`) => `CreateResult`<`T`, `O`, `F`, `R`\>

Expand Down Expand Up @@ -322,7 +314,7 @@ expect(state.arr).toBe(baseState.arr);

#### Defined in

[create.ts:55](/~https://github.com/unadlib/mutative/blob/66089ec/src/create.ts#L55)
[create.ts:61](/~https://github.com/unadlib/mutative/blob/557d56b/src/create.ts#L61)

**create**<`T`, `O`, `F`\>(`base`, `options?`): [`T`, () => `Result`<`T`, `O`, `F`\>]

Expand All @@ -347,7 +339,7 @@ expect(state.arr).toBe(baseState.arr);

#### Defined in

[create.ts:65](/~https://github.com/unadlib/mutative/blob/66089ec/src/create.ts#L65)
[create.ts:71](/~https://github.com/unadlib/mutative/blob/557d56b/src/create.ts#L71)

___

Expand Down Expand Up @@ -390,7 +382,7 @@ const state = create(

#### Defined in

[current.ts:79](/~https://github.com/unadlib/mutative/blob/66089ec/src/current.ts#L79)
[current.ts:81](/~https://github.com/unadlib/mutative/blob/557d56b/src/current.ts#L81)

___

Expand All @@ -412,7 +404,7 @@ Check if the value is a draft

#### Defined in

[utils/draft.ts:11](/~https://github.com/unadlib/mutative/blob/66089ec/src/utils/draft.ts#L11)
[utils/draft.ts:11](/~https://github.com/unadlib/mutative/blob/557d56b/src/utils/draft.ts#L11)

___

Expand All @@ -436,7 +428,7 @@ Check if a value is draftable

#### Defined in

[utils/draft.ts:28](/~https://github.com/unadlib/mutative/blob/66089ec/src/utils/draft.ts#L28)
[utils/draft.ts:28](/~https://github.com/unadlib/mutative/blob/557d56b/src/utils/draft.ts#L28)

___

Expand Down Expand Up @@ -479,7 +471,7 @@ const state = create(

#### Defined in

[original.ts:21](/~https://github.com/unadlib/mutative/blob/66089ec/src/original.ts#L21)
[original.ts:21](/~https://github.com/unadlib/mutative/blob/557d56b/src/original.ts#L21)

___

Expand Down Expand Up @@ -507,7 +499,7 @@ It is used as a safe return value to ensure that this value replaces the finaliz

#### Defined in

[safeReturn.ts:6](/~https://github.com/unadlib/mutative/blob/66089ec/src/safeReturn.ts#L6)
[safeReturn.ts:6](/~https://github.com/unadlib/mutative/blob/557d56b/src/safeReturn.ts#L6)

___

Expand Down Expand Up @@ -562,4 +554,4 @@ expect(state.foobar.bar).toBe(2);

#### Defined in

[unsafe.ts:53](/~https://github.com/unadlib/mutative/blob/66089ec/src/unsafe.ts#L53)
[unsafe.ts:53](/~https://github.com/unadlib/mutative/blob/557d56b/src/unsafe.ts#L53)
8 changes: 4 additions & 4 deletions docs/interfaces/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Enable autoFreeze, and return frozen state.

#### Defined in

[interface.ts:104](/~https://github.com/unadlib/mutative/blob/66089ec/src/interface.ts#L104)
[interface.ts:122](/~https://github.com/unadlib/mutative/blob/557d56b/src/interface.ts#L122)

___

Expand All @@ -40,7 +40,7 @@ Enable patch, and return the patches and inversePatches.

#### Defined in

[interface.ts:100](/~https://github.com/unadlib/mutative/blob/66089ec/src/interface.ts#L100)
[interface.ts:118](/~https://github.com/unadlib/mutative/blob/557d56b/src/interface.ts#L118)

___

Expand All @@ -53,7 +53,7 @@ And it can also return a shallow copy function(AutoFreeze and Patches should bot

#### Defined in

[interface.ts:109](/~https://github.com/unadlib/mutative/blob/66089ec/src/interface.ts#L109)
[interface.ts:127](/~https://github.com/unadlib/mutative/blob/557d56b/src/interface.ts#L127)

___

Expand All @@ -65,4 +65,4 @@ In strict mode, Forbid accessing non-draftable values and forbid returning a non

#### Defined in

[interface.ts:96](/~https://github.com/unadlib/mutative/blob/66089ec/src/interface.ts#L96)
[interface.ts:114](/~https://github.com/unadlib/mutative/blob/557d56b/src/interface.ts#L114)
17 changes: 8 additions & 9 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,23 @@ export interface ProxyDraft<T = any> {
callbacks?: ((patches?: Patches, inversePatches?: Patches) => void)[];
}

interface IPatch {
op: typeof Operation[keyof typeof Operation];
value?: any;
}

export type Patch<P extends PatchesOptions = any> = P extends {
pathAsArray: false;
}
? {
op: typeof Operation[keyof typeof Operation];
? IPatch & {
path: string;
value?: any;
}
: P extends true | object
? {
op: typeof Operation[keyof typeof Operation];
? IPatch & {
path: (string | number)[];
value?: any;
}
: {
op: typeof Operation[keyof typeof Operation];
: IPatch & {
path: string | (string | number)[];
value?: any;
};

export type Patches<P extends PatchesOptions = any> = Patch<P>[];
Expand Down

0 comments on commit 2ef61ce

Please sign in to comment.