const view = document.querySelector('aparte-diff');
view.diff = {
path: 'src/parse.ts',
before: [
'export function parse(input: string): number {',
' let total = 0;',
' for (const [, amount, unit] of input.matchAll(TOKEN)) {',
' total += parseInt(amount, 10) * UNITS[unit];',
' }',
' return total;',
'}',
'',
].join('\n'),
after: [
'export function parse(input: string): number {',
' let total = 0;',
' for (const [, amount, unit] of input.matchAll(TOKEN)) {',
' total += Number(amount) * UNITS[unit];',
' }',
" if (total === 0) throw new RangeError('Nothing to parse');",
' return total;',
'}',
'',
].join('\n'),
};
// The element keeps no comment: your app does, and hands them back to be shown.
const comments = [
{ path: 'src/parse.ts', side: 'new', startLine: 4, endLine: 4, text: 'Number keeps the fraction: 1.5h is ninety minutes now.', state: 'sent' },
];
view.comments = comments;
view.addEventListener('aparte-diff-comment', (event) => {
comments.push({ ...event.detail, state: 'pending' });
view.comments = comments;
});