How to add/update/delete annotations based on condition?

Which product are you using?
PDF.js Express

PDF.js Express Version
8.0.1

Detailed description of issue
When the event “annotationChanged” will call, I want to add/update/delete annotations based on conditions otherwise not. But now it always add/update/delete annotations even after I added my conditions.

Expected behaviour
After checking my condition. No annotation should be added/updated/deleted.

Does your issue happen with every document, or just one?
Issue happens with every document

Code snippet

annotationManager.addEventListener('annotationChanged', (annotations, action, { imported }) => {
      if (imported) {
        return;
      } else if(myCondition){
        // do something and return.
        return;
      } else {
        if (action === 'add') {
        console.log('this is a change that added annotations');
      } else if (action === 'modify') {
        console.log('this change modified annotations');
      } else if (action === 'delete') {
        console.log('there were annotations deleted');
      }
      }
    });

Thanks

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:APIs:Forums:

Hi Arman,

Because the event listener is just listening to events, trying to return from this method will not have an effect on the actual actions.

If you want to disable these actions, I would recommend enabling the read only mode.

Best Regards,
Zach Serviss
Web Development Support Engineer
PDFTron Systems, Inc.