Skip to content

Commit

Permalink
Subscribe docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Sep 25, 2023
1 parent 3fc5d4e commit 728e7e3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions website/docs/api_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ keywords:
promisify,
compose,
staticSuite,
subscrib,
]
---

Expand All @@ -59,6 +60,7 @@ Below is a list of all the API functions exposed by Vest.
- [suite.remove](./writing_your_suite/vests_suite.md#removing-a-single-field-from-the-suite-state) - Removes a single field from the suite.
- [suite.reset](./writing_your_suite/vests_suite.md#cleaning-up-our-validation-state) - Resets the suite to its initial state.
- [suite.resetField](./writing_your_suite/vests_suite.md#cleaning-up-our-validation-state) - Resets a single field to an untested state.
- [suite.subscribe](./writing_your_suite/vests_suite.md#subscribing-to-suite-state-changes) - Subscribes to suite state changes.

- [staticSuite](./server_side_validations.md) - creates a stateless suite that is used for server side validations.

Expand Down
11 changes: 11 additions & 0 deletions website/docs/writing_your_suite/vests_suite.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,14 @@ To reset the validity of a single field, you can call `suite.resetField(fieldNam
In some cases, you may want to remove a field from the suite state. For example, when the user removes a dynamically added field. In this case, you can call `suite.remove(fieldName)` to remove the field from the state and cancel any pending async validations that might still be running.

Note that you don't need to use `suite.remove` very often, as most users can simply use `reset` and `omitWhen`.

## Subscribing to Suite State Changes

You can subscribe to changes in the suite state by calling `suite.subscribe(callback)`. The callback will be called whenever the suite state changes internally.

```js
suite.subscribe(() => {
const result = suite.get();
// ... Do something with the result
});
```

0 comments on commit 728e7e3

Please sign in to comment.