handler-element-exists.js 744 B

1234567891011121314151617181920212223242526272829303132
  1. import { getBlockConnection } from '../helper';
  2. function elementExists(block) {
  3. return new Promise((resolve, reject) => {
  4. this._sendMessageToTab(block)
  5. .then((data) => {
  6. const nextBlockId = getBlockConnection(block, data ? 1 : 2);
  7. if (!data && block.data.throwError) {
  8. const error = new Error('element-not-found');
  9. error.nextBlockId = nextBlockId;
  10. error.data = { selector: block.data.selector };
  11. reject(error);
  12. return;
  13. }
  14. resolve({
  15. data,
  16. nextBlockId,
  17. });
  18. })
  19. .catch((error) => {
  20. error.nextBlockId = getBlockConnection(block);
  21. reject(error);
  22. });
  23. });
  24. }
  25. export default elementExists;