Skip to content

Commit

Permalink
docs: updated trigger documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewcourtice committed Apr 16, 2021
1 parent 8797e7b commit 254f1af
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions docs/src/api-reference/store.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,45 +86,37 @@ The store `once` function is exactly the same as the [global once function](/api
This is convenience method for subscribing to before mutation events on the current store. This is the same as writing:

```javascript
on('mutation:before', event => {});
on('mutation:before', event => event.data);
```

### Arguments
- **callback** `function` - A callback with a payload as it's only argument
- **mutationName** `string | string[]` - The name of the mutation(s) to trigger the handler on
- **handler** `function` - A callback with mutation data as it's only argument
- arguments
- **event** [EventPayload](./types.html#eventpayload) - An optional payload provided when the event is published
- **data** [MutationEventData](./types.html#mutationeventdata)
- **data** [MutationEventData](./types.html#mutationeventdata) - A mutation data object containing the mutation name, payload and result
- returns: `void`
- example: `payload => console.log(payload)`
- example: `data => console.log(data)`

### Return Value
An [EventListener](./types.html#eventlistener).

### Example

```javascript
onBeforeMutation(event => {
if (event.data.mutation === 'set-name') {
console.log('set-name');
// Single mutation
onBeforeMutation('set-name', ({ mutation, payload, result }) => {});

// Multiple mutations
onBeforeMutation(['set-id', 'set-name'], ({ mutation, payload, result }) => {
if (mutation === 'set-id') {

}
});
```

## onAfterMutation
This is convenience method for subscribing to after mutation events on the current store. This is the same as writing:

```javascript
on('mutation:after', event => {});
```

`onAfterMutation` has exactly the same signature as [onBeforeMutation](#onbeforemutation).
This is convenience method for subscribing to after mutation events on the current store. `onAfterMutation` has exactly the same signature as [onBeforeMutation](#onbeforemutation).


## onMutationError
This is convenience method for subscribing to failed mutation events on the current store. This is the same as writing:

```javascript
on('mutation:error', event => {});
```

`onMutationError` has exactly the same signature as [onBeforeMutation](#onbeforemutation).
This is convenience method for subscribing to failed mutation events on the current store. `onMutationError` has exactly the same signature as [onBeforeMutation](#onbeforemutation).

1 comment on commit 254f1af

@vercel
Copy link

@vercel vercel bot commented on 254f1af Apr 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.