Skip to content

Commit

Permalink
Merge branch 'NilSet-path-cache-invalidation'
Browse files Browse the repository at this point in the history
  • Loading branch information
dmonad committed Jun 22, 2023
2 parents c398448 + 942c8a2 commit 65c4d40
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/utils/Transaction.js
Expand Up @@ -275,30 +275,30 @@ const cleanupTransactions = (transactionCleanups, i) => {
)
fs.push(() => {
// deep observe events
transaction.changedParentTypes.forEach((events, type) =>
fs.push(() => {
// We need to think about the possibility that the user transforms the
// Y.Doc in the event.
if (type._item === null || !type._item.deleted) {
events = events
.filter(event =>
event.target._item === null || !event.target._item.deleted
)
events
.forEach(event => {
event.currentTarget = type
})
// sort events by path length so that top-level events are fired first.
events
.sort((event1, event2) => event1.path.length - event2.path.length)
// We don't need to check for events.length
// because we know it has at least one element
callEventHandlerListeners(type._dEH, events, transaction)
}
})
)
fs.push(() => doc.emit('afterTransaction', [transaction, doc]))
transaction.changedParentTypes.forEach((events, type) => {
// We need to think about the possibility that the user transforms the
// Y.Doc in the event.
if (type._dEH.l.length > 0 && (type._item === null || !type._item.deleted)) {
events = events
.filter(event =>
event.target._item === null || !event.target._item.deleted
)
events
.forEach(event => {
event.currentTarget = type
// path is relative to the current target
event._path = null
})
// sort events by path length so that top-level events are fired first.
events
.sort((event1, event2) => event1.path.length - event2.path.length)
// We don't need to check for events.length
// because we know it has at least one element
callEventHandlerListeners(type._dEH, events, transaction)
}
})
})
fs.push(() => doc.emit('afterTransaction', [transaction, doc]))
callAll(fs, [])
if (transaction._needFormattingCleanup) {
cleanupYTextAfterTransaction(transaction)
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 65c4d40

Please sign in to comment.