The question is about EventLogger. There are a total of four parts. Part 4 seems to be new.
In codesandbox, you are provided with:
- Some HTML and CSS that do not need to be modified, to render some small squares (only used in Part 1).
- A utils file that does not need to be modified, providing a fake async function to simulate uploading events.
- A basic outline of the EventLogger class, with only a prototype of the logEvent function.
- An index.js file used to call the EventLogger class.
Part 1
You need to use JavaScript’s built-in DOM querying functions to find these squares, then add a click handler to each square to log an event each time it is clicked. The event needs to include some information, such as the color of the square and the current time.
Part 2
Starting from Part 2, you do not need to worry about the previous squares. The interviewer will paste some test cases for you. Uploading each event once is not efficient enough. Now you need to add an interval where events that come in are placed in a batch and uploaded at the end.
Part 3
If each request to upload events takes a relatively long time, and there are other batches of events waiting to be uploaded during this time, you need to wait for the current upload to complete. The provided upload utility function will return a promise.
Part 4
If a request being uploaded takes more than three seconds, it needs to be aborted (the provided helper function includes this function). The aborted batch needs to be merged with the next batch to be uploaded before being uploaded again.