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

top level await example updated with await keyword #29

Closed
wants to merge 1 commit into from
Closed
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
42 changes: 20 additions & 22 deletions module-examples/top-level-await/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import colors from './modules/getColors.js';
import { Canvas } from './modules/canvas.js';
import colors from './modules/getColors.js';
// top level await
let squareModule = await import('./modules/square.js');
let circleModule = await import('./modules/circle.js');
let triangleModule = await import('./modules/triangle.js');

let circleBtn = document.querySelector('.circle');
let squareBtn = document.querySelector('.square');
Expand All @@ -11,31 +15,25 @@ myCanvas.create();
myCanvas.createReportList();

// draw a square
squareBtn.addEventListener('click', () => {
import('./modules/square.js').then((Module) => {
let square1 = new Module.Square(myCanvas.ctx, myCanvas.listId, 50, 50, 100, colors.blue);
square1.draw();
square1.reportArea();
square1.reportPerimeter();
})
squareBtn.addEventListener('click',() => {
let square = new squareModule.Square(myCanvas.ctx, myCanvas.listId, 50, 50, 100, colors.blue);
square.draw();
square.reportArea();
square.reportPerimeter();
});

// draw a circle
circleBtn.addEventListener('click', () => {
import('./modules/circle.js').then((Module) => {
let circle1 = new Module.Circle(myCanvas.ctx, myCanvas.listId, 75, 200, 100, colors.green);
circle1.draw();
circle1.reportArea();
circle1.reportPerimeter();
})
circleBtn.addEventListener('click', () => {
let circle = new circleModule.Circle(myCanvas.ctx, myCanvas.listId, 75, 200, 100, colors.green);
circle.draw();
circle.reportArea();
circle.reportPerimeter();
});

// draw a triangle
triangleBtn.addEventListener('click', () => {
import('./modules/triangle.js').then((Module) => {
let triangle1 = new Module.Triangle(myCanvas.ctx, myCanvas.listId, 100, 75, 190, colors.yellow);
triangle1.draw();
triangle1.reportArea();
triangle1.reportPerimeter();
})
triangleBtn.addEventListener('click', () => {
let triangle = new triangleModule.Triangle(myCanvas.ctx, myCanvas.listId, 100, 75, 190, colors.yellow);
triangle.draw();
triangle.reportArea();
triangle.reportPerimeter();
});
Loading