Skip to content

Commit f5f34e2

Browse files
committed
new: allow handleEvents handlers to massage/extract model data from event data
1 parent bc469d2 commit f5f34e2

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/service-module/make-service-plugin.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,18 @@ export default function prepareMakeServicePlugin(
117117
// (3^) Setup real-time events
118118
if (options.enableEvents) {
119119
const handleEvent = (eventName, item, mutationName) => {
120-
const affectsStore = options.handleEvents[eventName](item, {
120+
const handler = options.handleEvents[eventName]
121+
const confirmOrArray = handler(item, {
121122
model: Model,
122123
models: globalModels
123124
})
125+
const [affectsStore, modified = item] = Array.isArray(confirmOrArray)
126+
? confirmOrArray
127+
: [confirmOrArray]
124128
if (affectsStore) {
125129
eventName === 'removed'
126-
? store.commit(`${options.namespace}/removeItem`, item)
127-
: store.dispatch(`${options.namespace}/${mutationName}`, item)
130+
? store.commit(`${options.namespace}/removeItem`, modified)
131+
: store.dispatch(`${options.namespace}/${mutationName}`, modified)
128132
}
129133
}
130134

0 commit comments

Comments
 (0)