You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/service-plugin.md
+44Lines changed: 44 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -449,6 +449,50 @@ Each handler receives the following arguments:
449
449
-`model` The current service's Model class.
450
450
-`models` The same as the `$FeathersVuex` object, gives you access to each api with their respective model classes.
451
451
452
+
You do not have to specify a handler for every event. Any that are not specified in your service-specific `handleEvents`, will fall back to using the `handleEvents` handler in your global options. If none are defined for the service or globally, the default behavior is controlled by the `enableEvents` option.
If your application emits the standard Feathers service events inside a nested object with additional data, you can use `handleEvents` to tell FeathersVuex what part of that data is actually the model data that should be used to update the store.
457
+
458
+
To do this, use `handleEvents` as described before, but return a tuple `[affectsStore, modelData]` from your handler.
459
+
460
+
-`affectsStore` a truthy value indicates the event should update the store
461
+
-`modelData` is the model data used to update the store
462
+
463
+
For example, you've configured your Feathers API to emit `patched` events for your `Todos` service that include context about the event which look like
464
+
465
+
```json
466
+
{
467
+
"$context": {
468
+
"time": 1445411009000,
469
+
"userId": 121,
470
+
"deviceId": "Marty's iPhone"
471
+
},
472
+
"event": {
473
+
"id": 88,
474
+
"text": "Get back to the past",
475
+
"done": true
476
+
}
477
+
}
478
+
```
479
+
480
+
For this service to play nicely with FeathersVuex, you'll need to use `handleEvents`
481
+
482
+
```js
483
+
handleEvents: {
484
+
patched: (item, { model, models }) => {
485
+
// Perform any side effects...
486
+
487
+
// If the first element is truthy, the item will update the store
488
+
// The second element is the actual model data to add to the store
489
+
return [true, item.event]
490
+
}
491
+
}
492
+
```
493
+
494
+
The original event data is bubbled to [Model events](./model-classes.md#model-events) so listeners receive the full event context.
495
+
452
496
## Pagination and the `find` action
453
497
454
498
Both the `find` action and the `find` getter support pagination. There are differences in how they work.
0 commit comments