Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(eslint): add unicorn/prefer-add-event-listener rule #2867

Merged
merged 2 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ module.exports = {
],
'unicorn/prevent-abbreviations': 'error',
'unicorn/prefer-query-selector': 'error',
'unicorn/prefer-add-event-listener': 'error',
'import/newline-after-import': ['error', { count: 1 }],
'import/first': 'error',
'import/order': [
Expand Down
8 changes: 4 additions & 4 deletions dev/ts/component/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,21 @@ export function downloadAsPng(svg: string): void {
const canvas = document.createElement('canvas');
const canvasContext = canvas.getContext('2d');

imgPreview.onload = function () {
imgPreview.addEventListener('load', function () {
const img = new Image();
// B.2.0 not fully exported with client width/height, so use natural width/height
canvas.width = imgPreview.naturalWidth;
canvas.height = imgPreview.naturalHeight;
img.crossOrigin = 'Anonymous';
img.onload = function () {
img.addEventListener('load', function () {
canvasContext.drawImage(img, 0, 0);
URL.revokeObjectURL(svgUrl);
const pngInBase64 = canvas.toDataURL('image/png');
document.body.removeChild(imgPreview);
download('diagram.png', '', pngInBase64);
logDownload('Download completed');
};
});
img.src = imgPreview.src;
};
});
imgPreview.src = svgUrl;
}
2 changes: 1 addition & 1 deletion dev/ts/pages/elements-identification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ function resetTextArea(): void {

function configureControls(): void {
const selectedKindElt = document.querySelector('#bpmn-kinds-select') as HTMLSelectElement;
selectedKindElt.onchange = event => updateSelectedBPMNElements((event.target as HTMLSelectElement).value as ShapeBpmnElementKind);
selectedKindElt.addEventListener('change', event => updateSelectedBPMNElements((event.target as HTMLSelectElement).value as ShapeBpmnElementKind));
document.addEventListener('diagramLoaded', () => updateSelectedBPMNElements(selectedKindElt.value as ShapeBpmnElementKind), false);

document.querySelector('#clear-btn').addEventListener('click', function () {
Expand Down
4 changes: 2 additions & 2 deletions dev/ts/shared/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ function collapseBpmnElement(bpmnElementId: string): void {
// callback function for opening | dropping the file to be loaded
function readAndLoadFile(f: File): void {
const reader = new FileReader();
reader.onload = () => {
reader.addEventListener('load', () => {
loadBpmn(reader.result as string);
};
});
reader.readAsText(f);
}

Expand Down