Created
October 14, 2023 13:16
-
-
Save usrlocalben/b6a703a1fac2524220ecac0d5bd1915f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const events = ref([]); | |
// Map() of targetId -> event list | |
const targetEvents = computed(() => events.value | |
.filter(it => it.targetId !== undefined) | |
.reduce((ax, row) => ax.update(row.targetId, new List(), | |
items => items.push(row)), | |
new Map())); | |
const compacted = computed(() => { | |
const ax = []; | |
const visited = new Set(); | |
events.value.forEach(row => { | |
if (row.task === undefined) { | |
// root/global scope | |
ax.push(row) | |
} else { | |
// target scope | |
if (visited.has(row.targetId)) continue; | |
visited.add(row.targetId); | |
ax.push({targetId: row.targetId, | |
events: targetEvents.get(row.targetId).get('events').toArray()}); | |
} | |
}); | |
return ax; | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment