Skip to content

Commit 15f5fb1

Browse files
committed
feat(app): make handleEvents global
1 parent c9839f0 commit 15f5fb1

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

docs/getting-started.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,12 @@ const defaultOptions = {
286286
replaceItems: false,
287287
skipRequestIfExists: false,
288288
nameStyle: 'short',
289+
handleEvents: {
290+
created: (item, { model, models }) => options.enableEvents,
291+
patched: (item, { model, models }) => options.enableEvents,
292+
updated: (item, { model, models }) => options.enableEvents,
293+
removed: (item, { model, models }) => options.enableEvents
294+
},
289295
}
290296
```
291297
- `serverAlias` - **Default:** `api` - Models are keyed by `serverAlias`. Access the `$FeathersVuex` Plugin and its models in your components by `this.$FeathersVuex.api.${Model}`
@@ -298,11 +304,16 @@ const defaultOptions = {
298304
- `debug {Boolean}` - **Default:** `false` - Enable some logging for debugging
299305
- `addOnUpsert {Boolean}` - **Default:** `false` - If `true` add new records pushed by 'updated/patched' socketio events into store, instead of discarding them.
300306
- `autoRemove {Boolean}` - **Default:** `false` - If `true` automatically remove records missing from responses (only use with feathers-rest)
301-
- `enableEvents {Boolean}` - **Default:** `true` - If `false` socket event listeners will be turned off. See the services [handleEvents API](/service-plugin.html#configuration)
302307
- `preferUpdate {Boolean}` - **Default:** `false` - If `true`, calling `model.save()` will do an `update` instead of a `patch`.
303308
- `replaceItems {Boolean}` - **Default:** `false` - If `true`, updates & patches replace the record in the store. Default is false, which merges in changes.
304309
- `skipRequestIfExists {Boolean}` - **Default:** `false` - For get action, if `true` the record already exists in store, skip the remote request.
305310
- `nameStyle {'short'|'path'}` - **Default:** `'short'` - Use the full service path as the Vuex module name, instead of just the last section.
311+
- `enableEvents {Boolean}` - **Default:** `true` - If `false` socket event listeners will be turned off. See the services
312+
- `handleEvents {Object}`: For this to work `enableEvents` must be `true`
313+
- `created {Function}` - **Default:** `(item, { model, models }) => options.enableEvents` - handle `created` events, return true to add to the store
314+
- `patched {Function}` - **Default:** `(item, { model, models }) => options.enableEvents` - handle `created` events, return true to update in the store
315+
- `updated {Function}` - **Default:** `(item, { model, models }) => options.enableEvents` - handle `created` events, return true to update in the store
316+
- `removed {Function}` - **Default:** `(item, { model, models }) => options.enableEvents` - handle `removed` events, return true to remove from the store
306317

307318
Also see the [Configs per Service](/service-plugin.html#configuration)
308319

docs/service-plugin.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,17 @@ const servicePlugin = makeServicePlugin({
3232
debug: false,
3333
addOnUpsert: false,
3434
autoRemove: false,
35-
enableEvents: true,
3635
preferUpdate: false,
3736
replaceItems: false,
3837
skipRequestIfExists: false,
3938
nameStyle: 'short',
39+
enableEvents: true,
40+
handleEvents: {
41+
created: (item, { model, models }) => options.enableEvents,
42+
patched: (item, { model, models }) => options.enableEvents,
43+
updated: (item, { model, models }) => options.enableEvents,
44+
removed: (item, { model, models }) => options.enableEvents
45+
},
4046

4147
// optional and only configurable per service
4248
servicePath: '',
@@ -45,12 +51,6 @@ const servicePlugin = makeServicePlugin({
4551

4652
instanceDefaults: () => ({}),
4753
setupInstance: instance => instance,
48-
handleEvents: {
49-
created: (item, { model, models }) => options.enableEvents,
50-
patched: (item, { model, models }) => options.enableEvents,
51-
updated: (item, { model, models }) => options.enableEvents,
52-
removed: (item, { model, models }) => options.enableEvents
53-
},
5454

5555
state: {},
5656
getters: {},
@@ -67,11 +67,16 @@ The following options can also be configured in [Global Configuration](getting-s
6767
- `debug {Boolean}` - **Default:** `globalConfig: false` - Enable some logging for debugging
6868
- `addOnUpsert {Boolean}` - **Default:** `globalConfig: false` - If `true` add new records pushed by 'updated/patched' socketio events into store, instead of discarding them.
6969
- `autoRemove {Boolean}` - **Default:** `globalConfig: false` - If `true` automatically remove records missing from responses (only use with feathers-rest)
70-
- `enableEvents {Boolean}` - **Default:** `globalConfig: true` - If `false` socket event listeners will be turned off
7170
- `preferUpdate {Boolean}` - **Default:** `globalConfig: false` - If `true`, calling `model.save()` will do an `update` instead of a `patch`.
7271
- `replaceItems {Boolean}` - **Default:** `globalConfig: false` - If `true`, updates & patches replace the record in the store. Default is false, which merges in changes.
7372
- `skipRequestIfExists {Boolean}` - **Default:** `globalConfig: false` - For get action, if `true` the record already exists in store, skip the remote request.
7473
- `nameStyle {'short'|'path'}` - **Default:** `globalConfig: 'short'` - Use the full service path as the Vuex module name, instead of just the last section.
74+
- `enableEvents {Boolean}` - **Default:** `globalConfig: true` - If `false` socket event listeners will be turned off
75+
- `handleEvents {Object}`: For this to work `enableEvents` must be `true`
76+
- `created {Function}` - **Default:** `(item, { model, models }) => options.enableEvents` - handle `created` events, return true to add to the store
77+
- `patched {Function}` - **Default:** `(item, { model, models }) => options.enableEvents` - handle `created` events, return true to update in the store
78+
- `updated {Function}` - **Default:** `(item, { model, models }) => options.enableEvents` - handle `created` events, return true to update in the store
79+
- `removed {Function}` - **Default:** `(item, { model, models }) => options.enableEvents` - handle `removed` events, return true to remove from the store
7580

7681
The following options can only configured individually per service plugin
7782

@@ -80,11 +85,6 @@ The following options can only configured individually per service plugin
8085
- `modelName {String}` - **Default:** `${ServicePlugin.Model.modelName}`
8186
- `instanceDefaults {Function}` - **Default:** `() => ({})` - Override this method to provide default data for new instances. If using Model classes, specify this as a static class property.
8287
- `setupInstance {Function}` - **Default:** `instance => instance` - Override this method to setup data types or related data on an instance. If using Model classes, specify this as a static class property.
83-
- `handleEvents {Object}`: For this to work `enableEvents` must not be `false`
84-
- `created {Function}` - **Default:** `(item, { model, models }) => options.enableEvents` - handle `created` events, return true to add to the store
85-
- `patched {Function}` - **Default:** `(item, { model, models }) => options.enableEvents` - handle `created` events, return true to update in the store
86-
- `updated {Function}` - **Default:** `(item, { model, models }) => options.enableEvents` - handle `created` events, return true to update in the store
87-
- `removed {Function}` - **Default:** `(item, { model, models }) => options.enableEvents` - handle `removed` events, return true to remove from the store
8888

8989
- `state {Object}` - **Default:**: `null` - Pass custom `states` to the service plugin or modify existing ones
9090
- `getters {Object}` - **Default:** `null` - Pass custom `getters` to the service plugin or modify existing ones

0 commit comments

Comments
 (0)