Skip to content

Instantly share code, notes, and snippets.

@usrlocalben
Created October 14, 2023 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save usrlocalben/b6a703a1fac2524220ecac0d5bd1915f to your computer and use it in GitHub Desktop.
Save usrlocalben/b6a703a1fac2524220ecac0d5bd1915f to your computer and use it in GitHub Desktop.
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