Skip to content

Commit

Permalink
docs: add v3 migration guide
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Nov 28, 2020
1 parent 61d6258 commit 7412129
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/vest/docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
- [Excluding or including tests](./exclusion)
- [Using with node](./node)
- [Utilities](./utilities)
- [Migration Guides](./migration)
1 change: 1 addition & 0 deletions packages/vest/docs/_sidebar.md.bak
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
- [Excluding or including tests](./exclusion)
- [Using with node](./node)
- [Utilities](./utilities)
- [Migration Guides](./migration)
1 change: 1 addition & 0 deletions packages/vest/docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/docsify-themeable@0/dist/css/theme-simple.css"
/>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.22.0/themes/prism-tomorrow.css">
</head>
<body>
<div id="app"></div>
Expand Down
107 changes: 107 additions & 0 deletions packages/vest/docs/migration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Migration guides

## V2 to V3

Vest version 3 comes with many new features, yet with a reduced bundle size. To achieve this, some redundant interfaces were removed. All v2 capabilities still exist, but the way to use some of them changed.

**Replaced interfaces**

### Removed: vest.get()

From now on, use suite.get() to get the latest validation result.

#### v2

```js
const suite = vest.create('user_form', () => {
/*...*/
});

vest.get('user_form'); // Returns the most recent validation result
```

#### v3

```js
const suite = vest.create(() => {
/*...*/
});

suite.get(); // Returns the most recent validation result
```

### Removed: vest.reset() // To reset suite state

From now on, use suite.reset() to reset the validation result.

#### v2

```js
const suite = vest.create('user_form', () => {
/*...*/
});

vest.reset('user_form'); // Resets the validity state
```

#### v3

```js
const suite = vest.create(() => {
/*...*/
});

suite.reset(); // Resets the validity state
```

### Removed: vest.draft() // To retrieve intermediate result

From now on, use suite.get() to get the validation result.

#### v2

```js
const suite = vest.create('user_form', () => {
if (vest.draft().hasErrors('username')) {
/* ... */
}
});
```

#### v3

```js
const suite = vest.create('user_form', () => {
if (suite.get().hasErrors('username')) {
/* ... */
}
});
```

### Removed: validate() // For non persistent validations

The stateless validate export is not needed anymore due to a change in the state structure.

#### v2

```js
import { validate } from 'vest';

const result = data =>
validate('user_form', () => {
/*...*/
})();
```

#### v3

```js
import vest from 'vest';

const validate = data =>
vest.create(() => {
/* ... */
})();

const result = validate({ username: 'example' });
```

0 comments on commit 7412129

Please sign in to comment.