Skip to content

Commit

Permalink
invalidate cached path when changing currentTarget of event
Browse files Browse the repository at this point in the history
fixes #544
  • Loading branch information
NilSet committed Jun 19, 2023
1 parent c398448 commit 5d86247
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/utils/Transaction.js
Expand Up @@ -287,6 +287,7 @@ const cleanupTransactions = (transactionCleanups, i) => {
events
.forEach(event => {
event.currentTarget = type
event._path = null
})
// sort events by path length so that top-level events are fired first.
events
Expand Down
28 changes: 28 additions & 0 deletions tests/y-map.tests.js
Expand Up @@ -337,6 +337,34 @@ export const testObserversUsingObservedeep = tc => {
compare(users)
}

/**
* @param {t.TestCase} tc
*/
export const testPathsOfSiblingEvents = tc => {
const { users, map0 } = init(tc, { users: 2 })
/**
* @type {Array<Array<string|number>>}
*/
const pathes = []
let calls = 0
const doc = users[0]
map0.set('map', new Y.Map())
map0.get('map').set('text1', new Y.Text('initial'))
map0.observeDeep(events => {
events.forEach(event => {
pathes.push(event.path)
})
calls++
})
doc.transact(() => {
map0.get('map').get('text1').insert(0, 'post-')
map0.get('map').set('text2', new Y.Text('new'))
})
t.assert(calls === 1)
t.compare(pathes, [['map'], ['map', 'text1']])
compare(users)
}

// TODO: Test events in Y.Map
/**
* @param {Object<string,any>} is
Expand Down

0 comments on commit 5d86247

Please sign in to comment.