Skip to content

Commit bd71b4c

Browse files
authored
Merge pull request #274 from smartprocure/feature/call-onUpdateByOthers-after-results
Call onUpdateByOthers after results come back
2 parents b5cea68 + a264b8a commit bd71b4c

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

.changeset/dry-lamps-give.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'contexture-client': minor
3+
---
4+
5+
Run onUpdateByOthers after search results come back

packages/client/src/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,13 @@ export let ContextTree = _.curry(
139139
_.map((n) => {
140140
// When updated by others, force replace instead of merge response
141141
extend(n, { forceReplaceResponse: true })
142-
runTypeFunction(types, 'onUpdateByOthers', n, actionProps)
143142
}, updatedNodes)
144143
)
145144

145+
for (const n of _.remove({ path: snapshot(event.path) }, updatedNodes)) {
146+
extend(n, { wasUpdatedByOthers: true })
147+
}
148+
146149
// If disableAutoUpdate but this dispatch affects the target node, update *just* that node (to allow things like paging changes to always go through)
147150
// The assumption here is that any event that affects the target node would likely be assumed to take effect immediately by end users
148151
if (TreeInstance.disableAutoUpdate && affectsSelf)
@@ -229,6 +232,10 @@ export let ContextTree = _.curry(
229232
else {
230233
target.forceReplaceResponse = false
231234
extend(target, responseNode)
235+
if (target.wasUpdatedByOthers) {
236+
delete target.wasUpdatedByOthers
237+
runTypeFunction(types, 'onUpdateByOthers', target, actionProps)
238+
}
232239
}
233240
if (debug && node._meta) target.metaHistory.push(node._meta)
234241
}

packages/client/src/node.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export let internalStateKeys = [
3030
'onMarkForUpdate',
3131
'afterSearch',
3232
'forceReplaceResponse',
33+
'wasUpdatedByOthers',
3334
'expand',
3435
'collapse',
3536
]

0 commit comments

Comments
 (0)