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

Return object when onMissingElement is set to exception #291

Open
Antoine-Gerard opened this issue Mar 15, 2024 · 0 comments
Open

Return object when onMissingElement is set to exception #291

Antoine-Gerard opened this issue Mar 15, 2024 · 0 comments

Comments

@Antoine-Gerard
Copy link

Hello there,

I was wondering if it was possible to return an object when onMissingElement is set to 'exception'.

Sometimes I need to broadcast cards positioned according to a predefined order to my users. However, depending on what the user is looking for, the order may change or the card I'm using to position the new element with an insertAdjacentHtml may not be present on the page. I therefore use a specific method that allows me to deal with the error and find the position of the new card if necessary.

To make things easier, I'd need to know the operation that triggered the error, in order to retrieve the html and change the selector if necessary.

Something like this in cable_ready.js would be really great

const warning = `CableReady ${name ||
          ''} operation failed due to missing DOM element for selector: '${
          operation.selector
        }'`
       
switch (options.onMissingElement) {
     case 'ignore':
         break
     case 'event':
         dispatch(document, 'cable-ready:missing-element', {
              warning,
              operation
           })
           break
     case 'exception':
        throw { name: 'MissingDOMError', operation: operation }
     default:
          console.warn(warning)
      }
}

Thanks,
Antoine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant