How to use handleTopLevelImpl method in Playwright Internal

Best JavaScript code snippet using playwright-internal

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

ReactEventListener.js

Source: ReactEventListener.js Github

copy
1/* */ 
2(function(process) {
3  'use strict';
4  var EventListener = require("./EventListener");
5  var ExecutionEnvironment = require("./ExecutionEnvironment");
6  var PooledClass = require("./PooledClass");
7  var ReactInstanceHandles = require("./ReactInstanceHandles");
8  var ReactMount = require("./ReactMount");
9  var ReactUpdates = require("./ReactUpdates");
10  var assign = require("./Object.assign");
11  var getEventTarget = require("./getEventTarget");
12  var getUnboundedScrollPosition = require("./getUnboundedScrollPosition");
13  function findParent(node) {
14    var nodeID = ReactMount.getID(node);
15    var rootID = ReactInstanceHandles.getReactRootIDFromNodeID(nodeID);
16    var container = ReactMount.findReactContainerForID(rootID);
17    var parent = ReactMount.getFirstReactDOM(container);
18    return parent;
19  }
20  function TopLevelCallbackBookKeeping(topLevelType, nativeEvent) {
21    this.topLevelType = topLevelType;
22    this.nativeEvent = nativeEvent;
23    this.ancestors = [];
24  }
25  assign(TopLevelCallbackBookKeeping.prototype, {destructor: function() {
26      this.topLevelType = null;
27      this.nativeEvent = null;
28      this.ancestors.length = 0;
29    }});
30  PooledClass.addPoolingTo(TopLevelCallbackBookKeeping, PooledClass.twoArgumentPooler);
31  function handleTopLevelImpl(bookKeeping) {
32    var topLevelTarget = ReactMount.getFirstReactDOM(getEventTarget(bookKeeping.nativeEvent)) || window;
33    var ancestor = topLevelTarget;
34    while (ancestor) {
35      bookKeeping.ancestors.push(ancestor);
36      ancestor = findParent(ancestor);
37    }
38    for (var i = 0,
39        l = bookKeeping.ancestors.length; i < l; i++) {
40      topLevelTarget = bookKeeping.ancestors[i];
41      var topLevelTargetID = ReactMount.getID(topLevelTarget) || '';
42      ReactEventListener._handleTopLevel(bookKeeping.topLevelType, topLevelTarget, topLevelTargetID, bookKeeping.nativeEvent);
43    }
44  }
45  function scrollValueMonitor(cb) {
46    var scrollPosition = getUnboundedScrollPosition(window);
47    cb(scrollPosition);
48  }
49  var ReactEventListener = {
50    _enabled: true,
51    _handleTopLevel: null,
52    WINDOW_HANDLE: ExecutionEnvironment.canUseDOM ? window : null,
53    setHandleTopLevel: function(handleTopLevel) {
54      ReactEventListener._handleTopLevel = handleTopLevel;
55    },
56    setEnabled: function(enabled) {
57      ReactEventListener._enabled = !!enabled;
58    },
59    isEnabled: function() {
60      return ReactEventListener._enabled;
61    },
62    trapBubbledEvent: function(topLevelType, handlerBaseName, handle) {
63      var element = handle;
64      if (!element) {
65        return null;
66      }
67      return EventListener.listen(element, handlerBaseName, ReactEventListener.dispatchEvent.bind(null, topLevelType));
68    },
69    trapCapturedEvent: function(topLevelType, handlerBaseName, handle) {
70      var element = handle;
71      if (!element) {
72        return null;
73      }
74      return EventListener.capture(element, handlerBaseName, ReactEventListener.dispatchEvent.bind(null, topLevelType));
75    },
76    monitorScrollValue: function(refresh) {
77      var callback = scrollValueMonitor.bind(null, refresh);
78      EventListener.listen(window, 'scroll', callback);
79    },
80    dispatchEvent: function(topLevelType, nativeEvent) {
81      if (!ReactEventListener._enabled) {
82        return;
83      }
84      var bookKeeping = TopLevelCallbackBookKeeping.getPooled(topLevelType, nativeEvent);
85      try {
86        ReactUpdates.batchedUpdates(handleTopLevelImpl, bookKeeping);
87      } finally {
88        TopLevelCallbackBookKeeping.release(bookKeeping);
89      }
90    }
91  };
92  module.exports = ReactEventListener;
93})(require("process"));
94
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Playwright Internal on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)