Skip to content

Commit

Permalink
Migrated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
erikras committed Aug 19, 2019
1 parent 8fe4c0f commit 7b37726
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 97 deletions.
99 changes: 2 additions & 97 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,101 +11,6 @@ Mutators for updating array fields in

---

## Installation
## [Getting Started](https://final-form.org/docs/final-form-arrays/getting-started)

```bash
npm install --save final-form-arrays
```

or

```bash
yarn add final-form-arrays
```

## Usage

```js
import { createForm } from 'final-form'
import arrayMutators from 'final-form-arrays'

// Create Form
const form = createForm({
mutators: { ...arrayMutators },
onSubmit
})

// push
form.mutators.push('customers', { firstName: '', lastName: '' })

// pop
const customer = form.mutators.pop('customers')
```

## Table of Contents

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

- [Mutators](#mutators)
- [`form.mutators.concat(name: string, value: Array<any>) => void`](#formmutatorsconcatname-string-value-arrayany--void)
- [`form.mutators.insert(name: string, index: number, value: any) => undefined`](#formmutatorsinsertname-string-index-number-value-any--undefined)
- [`form.mutators.move(name: string, from: number, to: number) => undefined`](#formmutatorsmovename-string-from-number-to-number--undefined)
- [`form.mutators.pop(name: string) => any`](#formmutatorspopname-string--any)
- [`form.mutators.push(name: string, value: any) => void`](#formmutatorspushname-string-value-any--void)
- [`form.mutators.remove(name: string, index: number) => any`](#formmutatorsremovename-string-index-number--any)
- [`form.mutators.removeBatch(name: string, indexes: Array<number>) => undefined`](#formmutatorsremovebatchname-string-indexes-arraynumber--undefined)
- [`form.mutators.shift(name: string) => any`](#formmutatorsshiftname-string--any)
- [`form.mutators.swap(name: string, indexA: number, indexB: number) => void`](#formmutatorsswapname-string-indexa-number-indexb-number--void)
- [`form.mutators.update(name: string, index: number, value: any) => void`](#formmutatorsupdatename-string-index-number-value-any--void)
- [`form.mutators.unshift(name: string, value: any) => void`](#formmutatorsunshiftname-string-value-any--void)

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

## Mutators

### `form.mutators.concat(name: string, value: Array<any>) => void`

Concatenates an array at the end of the array field.

### `form.mutators.insert(name: string, index: number, value: any) => undefined`

Inserts a value into the specified index of the array field.

### `form.mutators.move(name: string, from: number, to: number) => undefined`

Moves a value from one index to another index in the array field.

### `form.mutators.pop(name: string) => any`

Pops a value off the end of an array field. Returns the value.

### `form.mutators.push(name: string, value: any) => void`

Pushes a value onto the end of an array field.

### `form.mutators.remove(name: string, index: number) => any`

Removes a value from the specified index of the array field. Returns the removed
value.

### `form.mutators.removeBatch(name: string, indexes: Array<number>) => undefined`

Removes the values at the specified indexes of the array field.

### `form.mutators.shift(name: string) => any`

Removes a value from the beginning of the array field. Returns the value.

### `form.mutators.swap(name: string, indexA: number, indexB: number) => void`

Swaps the position of two values in the array field.

### `form.mutators.update(name: string, index: number, value: any) => void`

Updates a value of the specified index of the array field.

### `form.mutators.unshift(name: string, value: any) => void`

Inserts a value onto the beginning of the array field.
## [API](https://final-form.org/docs/final-form-arrays/api)
98 changes: 98 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# This documentation is meant to be read on [final-form.org](https://final-form.org/docs/final-form-arrays/api). Links may not work on Github.com.

# API

This library provides the following Final Form [mutators](/docs/final-form/types/Mutator). They are intended to mimic the array mutations available [`Array.prototype`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/prototype) in JavaScript.

The `name` argument always refers to the field to be mutated.

### `form.mutators.concat`

```ts
(name: string, value: Array<any>) => void
```

Concatenates an array at the end of the field array.

### `form.mutators.insert`

```ts
(name: string, index: number, value: any) => void`
```

Inserts a value into the specified index of the field array.

### `form.mutators.move`

```ts
(name: string, from: number, to: number) => void
```

Moves a value from one index to another index in the field array.

### `form.mutators.pop`

<!-- prettier-ignore -->
```ts
(name: string) => any
```

Pops a value off the end of an field array. Returns the value.

### `form.mutators.push`

```ts
(name: string, value: any) => void
```

Pushes a value onto the end of an field array.

### `form.mutators.remove`

<!-- prettier-ignore -->
```ts
(name: string, index: number) => any
```

Removes a value from the specified index of the field array. Returns the removed value.

### `form.mutators.removeBatch`

```ts
(name: string, indexes: Array<number>) => void
```

Removes the values at the specified indexes of the field array.

### `form.mutators.shift`

<!-- prettier-ignore -->
```ts
(name: string) => any
```

Removes a value from the beginning of the field array. Returns the value.

### `form.mutators.swap`

```ts
(name: string, indexA: number, indexB: number) => void
```

Swaps the position of two values in the field array.

### `form.mutators.unshift`

```ts
(name: string, value: any) => void
```

Inserts a value onto the beginning of the field array.

### `form.mutators.update`

```ts
(name: string, index: number, value: any) => void
```

Updates a value of the specified index of the field array.
40 changes: 40 additions & 0 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This documentation is meant to be read on [final-form.org](https://final-form.org/docs/final-form-arrays/getting-started). Links may not work on Github.com.

# Getting Started

This library provides field array management functionality as a plugin [mutator](/docs/final-form/types/Mutator) to Final Form.

## Installation

```bash
npm install --save final-form final-form-arrays
```

or

```bash
yarn add final-form final-form-arrays
```

## Usage

```js
import { createForm } from 'final-form'
import arrayMutators from 'final-form-arrays'

// Create Form
const form = createForm({
mutators: { ...arrayMutators },
onSubmit
})

// push
form.mutators.push('customers', { firstName: '', lastName: '' })

// pop
const customer = form.mutators.pop('customers')
```

## Mutators

Check out the [API](api) to see all the mutators provided.

0 comments on commit 7b37726

Please sign in to comment.