How to use responder method in wpt

Best JavaScript code snippet using wpt

ResponderEventPlugin.js

Source:ResponderEventPlugin.js Github

copy

Full Screen

1/**2 * Copyright 2013-present, Facebook, Inc.3 * All rights reserved.4 *5 * This source code is licensed under the BSD-style license found in the6 * LICENSE file in the root directory of this source tree. An additional grant7 * of patent rights can be found in the PATENTS file in the same directory.8 *9 * @providesModule ResponderEventPlugin10 */11'use strict';12var EventPluginUtils = require('EventPluginUtils');13var EventPropagators = require('EventPropagators');14var ReactTreeTraversal = require('ReactTreeTraversal');15var ResponderSyntheticEvent = require('ResponderSyntheticEvent');16var ResponderTouchHistoryStore = require('ResponderTouchHistoryStore');17var accumulate = require('accumulate');18var isStartish = EventPluginUtils.isStartish;19var isMoveish = EventPluginUtils.isMoveish;20var isEndish = EventPluginUtils.isEndish;21var executeDirectDispatch = EventPluginUtils.executeDirectDispatch;22var hasDispatches = EventPluginUtils.hasDispatches;23var executeDispatchesInOrderStopAtTrue = EventPluginUtils.executeDispatchesInOrderStopAtTrue;24/**25 * Instance of element that should respond to touch/move types of interactions,26 * as indicated explicitly by relevant callbacks.27 */28var responderInst = null;29/**30 * Count of current touches. A textInput should become responder iff the31 * selection changes while there is a touch on the screen.32 */33var trackedTouchCount = 0;34/**35 * Last reported number of active touches.36 */37var previousActiveTouches = 0;38var changeResponder = function(nextResponderInst, blockHostResponder) {39 var oldResponderInst = responderInst;40 responderInst = nextResponderInst;41 if (ResponderEventPlugin.GlobalResponderHandler !== null) {42 ResponderEventPlugin.GlobalResponderHandler.onChange(43 oldResponderInst,44 nextResponderInst,45 blockHostResponder,46 );47 }48};49var eventTypes = {50 /**51 * On a `touchStart`/`mouseDown`, is it desired that this element become the52 * responder?53 */54 startShouldSetResponder: {55 phasedRegistrationNames: {56 bubbled: 'onStartShouldSetResponder',57 captured: 'onStartShouldSetResponderCapture',58 },59 },60 /**61 * On a `scroll`, is it desired that this element become the responder? This62 * is usually not needed, but should be used to retroactively infer that a63 * `touchStart` had occurred during momentum scroll. During a momentum scroll,64 * a touch start will be immediately followed by a scroll event if the view is65 * currently scrolling.66 *67 * TODO: This shouldn't bubble.68 */69 scrollShouldSetResponder: {70 phasedRegistrationNames: {71 bubbled: 'onScrollShouldSetResponder',72 captured: 'onScrollShouldSetResponderCapture',73 },74 },75 /**76 * On text selection change, should this element become the responder? This77 * is needed for text inputs or other views with native selection, so the78 * JS view can claim the responder.79 *80 * TODO: This shouldn't bubble.81 */82 selectionChangeShouldSetResponder: {83 phasedRegistrationNames: {84 bubbled: 'onSelectionChangeShouldSetResponder',85 captured: 'onSelectionChangeShouldSetResponderCapture',86 },87 },88 /**89 * On a `touchMove`/`mouseMove`, is it desired that this element become the90 * responder?91 */92 moveShouldSetResponder: {93 phasedRegistrationNames: {94 bubbled: 'onMoveShouldSetResponder',95 captured: 'onMoveShouldSetResponderCapture',96 },97 },98 /**99 * Direct responder events dispatched directly to responder. Do not bubble.100 */101 responderStart: {registrationName: 'onResponderStart'},102 responderMove: {registrationName: 'onResponderMove'},103 responderEnd: {registrationName: 'onResponderEnd'},104 responderRelease: {registrationName: 'onResponderRelease'},105 responderTerminationRequest: {106 registrationName: 'onResponderTerminationRequest',107 },108 responderGrant: {registrationName: 'onResponderGrant'},109 responderReject: {registrationName: 'onResponderReject'},110 responderTerminate: {registrationName: 'onResponderTerminate'},111};112/**113 *114 * Responder System:115 * ----------------116 *117 * - A global, solitary "interaction lock" on a view.118 * - If a node becomes the responder, it should convey visual feedback119 * immediately to indicate so, either by highlighting or moving accordingly.120 * - To be the responder means, that touches are exclusively important to that121 * responder view, and no other view.122 * - While touches are still occurring, the responder lock can be transferred to123 * a new view, but only to increasingly "higher" views (meaning ancestors of124 * the current responder).125 *126 * Responder being granted:127 * ------------------------128 *129 * - Touch starts, moves, and scrolls can cause an ID to become the responder.130 * - We capture/bubble `startShouldSetResponder`/`moveShouldSetResponder` to131 * the "appropriate place".132 * - If nothing is currently the responder, the "appropriate place" is the133 * initiating event's `targetID`.134 * - If something *is* already the responder, the "appropriate place" is the135 * first common ancestor of the event target and the current `responderInst`.136 * - Some negotiation happens: See the timing diagram below.137 * - Scrolled views automatically become responder. The reasoning is that a138 * platform scroll view that isn't built on top of the responder system has139 * began scrolling, and the active responder must now be notified that the140 * interaction is no longer locked to it - the system has taken over.141 *142 * - Responder being released:143 * As soon as no more touches that *started* inside of descendants of the144 * *current* responderInst, an `onResponderRelease` event is dispatched to the145 * current responder, and the responder lock is released.146 *147 * TODO:148 * - on "end", a callback hook for `onResponderEndShouldRemainResponder` that149 * determines if the responder lock should remain.150 * - If a view shouldn't "remain" the responder, any active touches should by151 * default be considered "dead" and do not influence future negotiations or152 * bubble paths. It should be as if those touches do not exist.153 * -- For multitouch: Usually a translate-z will choose to "remain" responder154 * after one out of many touches ended. For translate-y, usually the view155 * doesn't wish to "remain" responder after one of many touches end.156 * - Consider building this on top of a `stopPropagation` model similar to157 * `W3C` events.158 * - Ensure that `onResponderTerminate` is called on touch cancels, whether or159 * not `onResponderTerminationRequest` returns `true` or `false`.160 *161 */162/* Negotiation Performed163 +-----------------------+164 / \165Process low level events to + Current Responder + wantsResponderID166determine who to perform negot-| (if any exists at all) |167iation/transition | Otherwise just pass through|168-------------------------------+----------------------------+------------------+169Bubble to find first ID | |170to return true:wantsResponderID| |171 | |172 +-------------+ | |173 | onTouchStart| | |174 +------+------+ none | |175 | return| |176+-----------v-------------+true| +------------------------+ |177|onStartShouldSetResponder|----->|onResponderStart (cur) |<-----------+178+-----------+-------------+ | +------------------------+ | |179 | | | +--------+-------+180 | returned true for| false:REJECT +-------->|onResponderReject181 | wantsResponderID | | | +----------------+182 | (now attempt | +------------------+-----+ |183 | handoff) | | onResponder | |184 +------------------->| TerminationRequest| |185 | +------------------+-----+ |186 | | | +----------------+187 | true:GRANT +-------->|onResponderGrant|188 | | +--------+-------+189 | +------------------------+ | |190 | | onResponderTerminate |<-----------+191 | +------------------+-----+ |192 | | | +----------------+193 | +-------->|onResponderStart|194 | | +----------------+195Bubble to find first ID | |196to return true:wantsResponderID| |197 | |198 +-------------+ | |199 | onTouchMove | | |200 +------+------+ none | |201 | return| |202+-----------v-------------+true| +------------------------+ |203|onMoveShouldSetResponder |----->|onResponderMove (cur) |<-----------+204+-----------+-------------+ | +------------------------+ | |205 | | | +--------+-------+206 | returned true for| false:REJECT +-------->|onResponderRejec|207 | wantsResponderID | | | +----------------+208 | (now attempt | +------------------+-----+ |209 | handoff) | | onResponder | |210 +------------------->| TerminationRequest| |211 | +------------------+-----+ |212 | | | +----------------+213 | true:GRANT +-------->|onResponderGrant|214 | | +--------+-------+215 | +------------------------+ | |216 | | onResponderTerminate |<-----------+217 | +------------------+-----+ |218 | | | +----------------+219 | +-------->|onResponderMove |220 | | +----------------+221 | |222 | |223 Some active touch started| |224 inside current responder | +------------------------+ |225 +------------------------->| onResponderEnd | |226 | | +------------------------+ |227 +---+---------+ | |228 | onTouchEnd | | |229 +---+---------+ | |230 | | +------------------------+ |231 +------------------------->| onResponderEnd | |232 No active touches started| +-----------+------------+ |233 inside current responder | | |234 | v |235 | +------------------------+ |236 | | onResponderRelease | |237 | +------------------------+ |238 | |239 + + */240/**241 * A note about event ordering in the `EventPluginHub`.242 *243 * Suppose plugins are injected in the following order:244 *245 * `[R, S, C]`246 *247 * To help illustrate the example, assume `S` is `SimpleEventPlugin` (for248 * `onClick` etc) and `R` is `ResponderEventPlugin`.249 *250 * "Deferred-Dispatched Events":251 *252 * - The current event plugin system will traverse the list of injected plugins,253 * in order, and extract events by collecting the plugin's return value of254 * `extractEvents()`.255 * - These events that are returned from `extractEvents` are "deferred256 * dispatched events".257 * - When returned from `extractEvents`, deferred-dispatched events contain an258 * "accumulation" of deferred dispatches.259 * - These deferred dispatches are accumulated/collected before they are260 * returned, but processed at a later time by the `EventPluginHub` (hence the261 * name deferred).262 *263 * In the process of returning their deferred-dispatched events, event plugins264 * themselves can dispatch events on-demand without returning them from265 * `extractEvents`. Plugins might want to do this, so that they can use event266 * dispatching as a tool that helps them decide which events should be extracted267 * in the first place.268 *269 * "On-Demand-Dispatched Events":270 *271 * - On-demand-dispatched events are not returned from `extractEvents`.272 * - On-demand-dispatched events are dispatched during the process of returning273 * the deferred-dispatched events.274 * - They should not have side effects.275 * - They should be avoided, and/or eventually be replaced with another276 * abstraction that allows event plugins to perform multiple "rounds" of event277 * extraction.278 *279 * Therefore, the sequence of event dispatches becomes:280 *281 * - `R`s on-demand events (if any) (dispatched by `R` on-demand)282 * - `S`s on-demand events (if any) (dispatched by `S` on-demand)283 * - `C`s on-demand events (if any) (dispatched by `C` on-demand)284 * - `R`s extracted events (if any) (dispatched by `EventPluginHub`)285 * - `S`s extracted events (if any) (dispatched by `EventPluginHub`)286 * - `C`s extracted events (if any) (dispatched by `EventPluginHub`)287 *288 * In the case of `ResponderEventPlugin`: If the `startShouldSetResponder`289 * on-demand dispatch returns `true` (and some other details are satisfied) the290 * `onResponderGrant` deferred dispatched event is returned from291 * `extractEvents`. The sequence of dispatch executions in this case292 * will appear as follows:293 *294 * - `startShouldSetResponder` (`ResponderEventPlugin` dispatches on-demand)295 * - `touchStartCapture` (`EventPluginHub` dispatches as usual)296 * - `touchStart` (`EventPluginHub` dispatches as usual)297 * - `responderGrant/Reject` (`EventPluginHub` dispatches as usual)298 */299function setResponderAndExtractTransfer(300 topLevelType,301 targetInst,302 nativeEvent,303 nativeEventTarget,304) {305 var shouldSetEventType = isStartish(topLevelType)306 ? eventTypes.startShouldSetResponder307 : isMoveish(topLevelType)308 ? eventTypes.moveShouldSetResponder309 : topLevelType === 'topSelectionChange'310 ? eventTypes.selectionChangeShouldSetResponder311 : eventTypes.scrollShouldSetResponder;312 // TODO: stop one short of the current responder.313 var bubbleShouldSetFrom = !responderInst314 ? targetInst315 : ReactTreeTraversal.getLowestCommonAncestor(responderInst, targetInst);316 // When capturing/bubbling the "shouldSet" event, we want to skip the target317 // (deepest ID) if it happens to be the current responder. The reasoning:318 // It's strange to get an `onMoveShouldSetResponder` when you're *already*319 // the responder.320 var skipOverBubbleShouldSetFrom = bubbleShouldSetFrom === responderInst;321 var shouldSetEvent = ResponderSyntheticEvent.getPooled(322 shouldSetEventType,323 bubbleShouldSetFrom,324 nativeEvent,325 nativeEventTarget,326 );327 shouldSetEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;328 if (skipOverBubbleShouldSetFrom) {329 EventPropagators.accumulateTwoPhaseDispatchesSkipTarget(shouldSetEvent);330 } else {331 EventPropagators.accumulateTwoPhaseDispatches(shouldSetEvent);332 }333 var wantsResponderInst = executeDispatchesInOrderStopAtTrue(shouldSetEvent);334 if (!shouldSetEvent.isPersistent()) {335 shouldSetEvent.constructor.release(shouldSetEvent);336 }337 if (!wantsResponderInst || wantsResponderInst === responderInst) {338 return null;339 }340 var extracted;341 var grantEvent = ResponderSyntheticEvent.getPooled(342 eventTypes.responderGrant,343 wantsResponderInst,344 nativeEvent,345 nativeEventTarget,346 );347 grantEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;348 EventPropagators.accumulateDirectDispatches(grantEvent);349 var blockHostResponder = executeDirectDispatch(grantEvent) === true;350 if (responderInst) {351 var terminationRequestEvent = ResponderSyntheticEvent.getPooled(352 eventTypes.responderTerminationRequest,353 responderInst,354 nativeEvent,355 nativeEventTarget,356 );357 terminationRequestEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;358 EventPropagators.accumulateDirectDispatches(terminationRequestEvent);359 var shouldSwitch = !hasDispatches(terminationRequestEvent) ||360 executeDirectDispatch(terminationRequestEvent);361 if (!terminationRequestEvent.isPersistent()) {362 terminationRequestEvent.constructor.release(terminationRequestEvent);363 }364 if (shouldSwitch) {365 var terminateEvent = ResponderSyntheticEvent.getPooled(366 eventTypes.responderTerminate,367 responderInst,368 nativeEvent,369 nativeEventTarget,370 );371 terminateEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;372 EventPropagators.accumulateDirectDispatches(terminateEvent);373 extracted = accumulate(extracted, [grantEvent, terminateEvent]);374 changeResponder(wantsResponderInst, blockHostResponder);375 } else {376 var rejectEvent = ResponderSyntheticEvent.getPooled(377 eventTypes.responderReject,378 wantsResponderInst,379 nativeEvent,380 nativeEventTarget,381 );382 rejectEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;383 EventPropagators.accumulateDirectDispatches(rejectEvent);384 extracted = accumulate(extracted, rejectEvent);385 }386 } else {387 extracted = accumulate(extracted, grantEvent);388 changeResponder(wantsResponderInst, blockHostResponder);389 }390 return extracted;391}392/**393 * A transfer is a negotiation between a currently set responder and the next394 * element to claim responder status. Any start event could trigger a transfer395 * of responderInst. Any move event could trigger a transfer.396 *397 * @param {string} topLevelType Record from `EventConstants`.398 * @return {boolean} True if a transfer of responder could possibly occur.399 */400function canTriggerTransfer(topLevelType, topLevelInst, nativeEvent) {401 return topLevelInst &&402 // responderIgnoreScroll: We are trying to migrate away from specifically403 // tracking native scroll events here and responderIgnoreScroll indicates we404 // will send topTouchCancel to handle canceling touch events instead405 ((topLevelType === 'topScroll' && !nativeEvent.responderIgnoreScroll) ||406 (trackedTouchCount > 0 && topLevelType === 'topSelectionChange') ||407 isStartish(topLevelType) ||408 isMoveish(topLevelType));409}410/**411 * Returns whether or not this touch end event makes it such that there are no412 * longer any touches that started inside of the current `responderInst`.413 *414 * @param {NativeEvent} nativeEvent Native touch end event.415 * @return {boolean} Whether or not this touch end event ends the responder.416 */417function noResponderTouches(nativeEvent) {418 var touches = nativeEvent.touches;419 if (!touches || touches.length === 0) {420 return true;421 }422 for (var i = 0; i < touches.length; i++) {423 var activeTouch = touches[i];424 var target = activeTouch.target;425 if (target !== null && target !== undefined && target !== 0) {426 // Is the original touch location inside of the current responder?427 var targetInst = EventPluginUtils.getInstanceFromNode(target);428 if (ReactTreeTraversal.isAncestor(responderInst, targetInst)) {429 return false;430 }431 }432 }433 return true;434}435var ResponderEventPlugin = {436 /* For unit testing only */437 _getResponder: function() {438 return responderInst;439 },440 eventTypes: eventTypes,441 /**442 * We must be resilient to `targetInst` being `null` on `touchMove` or443 * `touchEnd`. On certain platforms, this means that a native scroll has444 * assumed control and the original touch targets are destroyed.445 */446 extractEvents: function(447 topLevelType,448 targetInst,449 nativeEvent,450 nativeEventTarget,451 ) {452 if (isStartish(topLevelType)) {453 trackedTouchCount += 1;454 } else if (isEndish(topLevelType)) {455 if (trackedTouchCount >= 0) {456 trackedTouchCount -= 1;457 } else {458 console.error(459 'Ended a touch event which was not counted in `trackedTouchCount`.',460 );461 return null;462 }463 }464 ResponderTouchHistoryStore.recordTouchTrack(topLevelType, nativeEvent);465 var extracted = canTriggerTransfer(topLevelType, targetInst, nativeEvent)466 ? setResponderAndExtractTransfer(467 topLevelType,468 targetInst,469 nativeEvent,470 nativeEventTarget,471 )472 : null;473 // Responder may or may not have transferred on a new touch start/move.474 // Regardless, whoever is the responder after any potential transfer, we475 // direct all touch start/move/ends to them in the form of476 // `onResponderMove/Start/End`. These will be called for *every* additional477 // finger that move/start/end, dispatched directly to whoever is the478 // current responder at that moment, until the responder is "released".479 //480 // These multiple individual change touch events are are always bookended481 // by `onResponderGrant`, and one of482 // (`onResponderRelease/onResponderTerminate`).483 var isResponderTouchStart = responderInst && isStartish(topLevelType);484 var isResponderTouchMove = responderInst && isMoveish(topLevelType);485 var isResponderTouchEnd = responderInst && isEndish(topLevelType);486 var incrementalTouch = isResponderTouchStart487 ? eventTypes.responderStart488 : isResponderTouchMove489 ? eventTypes.responderMove490 : isResponderTouchEnd ? eventTypes.responderEnd : null;491 if (incrementalTouch) {492 var gesture = ResponderSyntheticEvent.getPooled(493 incrementalTouch,494 responderInst,495 nativeEvent,496 nativeEventTarget,497 );498 gesture.touchHistory = ResponderTouchHistoryStore.touchHistory;499 EventPropagators.accumulateDirectDispatches(gesture);500 extracted = accumulate(extracted, gesture);501 }502 var isResponderTerminate = responderInst &&503 topLevelType === 'topTouchCancel';504 var isResponderRelease = responderInst &&505 !isResponderTerminate &&506 isEndish(topLevelType) &&507 noResponderTouches(nativeEvent);508 var finalTouch = isResponderTerminate509 ? eventTypes.responderTerminate510 : isResponderRelease ? eventTypes.responderRelease : null;511 if (finalTouch) {512 var finalEvent = ResponderSyntheticEvent.getPooled(513 finalTouch,514 responderInst,515 nativeEvent,516 nativeEventTarget,517 );518 finalEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;519 EventPropagators.accumulateDirectDispatches(finalEvent);520 extracted = accumulate(extracted, finalEvent);521 changeResponder(null);522 }523 var numberActiveTouches = ResponderTouchHistoryStore.touchHistory.numberActiveTouches;524 if (525 ResponderEventPlugin.GlobalInteractionHandler &&526 numberActiveTouches !== previousActiveTouches527 ) {528 ResponderEventPlugin.GlobalInteractionHandler.onChange(529 numberActiveTouches,530 );531 }532 previousActiveTouches = numberActiveTouches;533 return extracted;534 },535 GlobalResponderHandler: null,536 GlobalInteractionHandler: null,537 injection: {538 /**539 * @param {{onChange: (ReactID, ReactID) => void} GlobalResponderHandler540 * Object that handles any change in responder. Use this to inject541 * integration with an existing touch handling system etc.542 */543 injectGlobalResponderHandler: function(GlobalResponderHandler) {544 ResponderEventPlugin.GlobalResponderHandler = GlobalResponderHandler;545 },546 /**547 * @param {{onChange: (numberActiveTouches) => void} GlobalInteractionHandler548 * Object that handles any change in the number of active touches.549 */550 injectGlobalInteractionHandler: function(GlobalInteractionHandler) {551 ResponderEventPlugin.GlobalInteractionHandler = GlobalInteractionHandler;552 },553 },554};...

Full Screen

Full Screen

ResponderEventPlugin-test.js

Source:ResponderEventPlugin-test.js Github

copy

Full Screen

1/**2 * @emails react-core3 */4"use strict";5var CallbackRegistry;6var EventConstants;7var EventPropagators;8var ReactInstanceHandles;9var ResponderEventPlugin;10var AbstractEvent;11var GRANDPARENT_ID = '.reactRoot[0]';12var PARENT_ID = '.reactRoot[0].0';13var CHILD_ID = '.reactRoot[0].0.0';14var topLevelTypes;15var responderAbstractEventTypes;16var spies;17var DUMMY_NATIVE_EVENT = {};18var DUMMY_RENDERED_TARGET = {};19var onStartShouldSetResponder = function(id, cb, capture) {20 var registrationNames = responderAbstractEventTypes21 .startShouldSetResponder22 .phasedRegistrationNames;23 CallbackRegistry.putListener(24 id,25 capture ? registrationNames.captured : registrationNames.bubbled,26 cb27 );28};29var onScrollShouldSetResponder = function(id, cb, capture) {30 var registrationNames = responderAbstractEventTypes31 .scrollShouldSetResponder32 .phasedRegistrationNames;33 CallbackRegistry.putListener(34 id,35 capture ? registrationNames.captured : registrationNames.bubbled,36 cb37 );38};39var onMoveShouldSetResponder = function(id, cb, capture) {40 var registrationNames = responderAbstractEventTypes41 .moveShouldSetResponder42 .phasedRegistrationNames;43 CallbackRegistry.putListener(44 id,45 capture ? registrationNames.captured : registrationNames.bubbled,46 cb47 );48};49var onResponderGrant = function(id, cb) {50 CallbackRegistry.putListener(51 id,52 responderAbstractEventTypes.responderGrant.registrationName,53 cb54 );55};56var extractForTouchStart = function(renderedTargetID) {57 return ResponderEventPlugin.extractAbstractEvents(58 topLevelTypes.topTouchStart,59 DUMMY_NATIVE_EVENT,60 renderedTargetID,61 DUMMY_RENDERED_TARGET62 );63};64var extractForTouchMove = function(renderedTargetID) {65 return ResponderEventPlugin.extractAbstractEvents(66 topLevelTypes.topTouchMove,67 DUMMY_NATIVE_EVENT,68 renderedTargetID,69 DUMMY_RENDERED_TARGET70 );71};72var extractForTouchEnd = function(renderedTargetID) {73 return ResponderEventPlugin.extractAbstractEvents(74 topLevelTypes.topTouchEnd,75 DUMMY_NATIVE_EVENT,76 renderedTargetID,77 DUMMY_RENDERED_TARGET78 );79};80var extractForMouseDown = function(renderedTargetID) {81 return ResponderEventPlugin.extractAbstractEvents(82 topLevelTypes.topMouseDown,83 DUMMY_NATIVE_EVENT,84 renderedTargetID,85 DUMMY_RENDERED_TARGET86 );87};88var extractForMouseMove = function(renderedTargetID) {89 return ResponderEventPlugin.extractAbstractEvents(90 topLevelTypes.topMouseMove,91 DUMMY_NATIVE_EVENT,92 renderedTargetID,93 DUMMY_RENDERED_TARGET94 );95};96var extractForMouseUp = function(renderedTargetID) {97 return ResponderEventPlugin.extractAbstractEvents(98 topLevelTypes.topMouseUp,99 DUMMY_NATIVE_EVENT,100 renderedTargetID,101 DUMMY_RENDERED_TARGET102 );103};104var extractForScroll = function(renderedTargetID) {105 return ResponderEventPlugin.extractAbstractEvents(106 topLevelTypes.topScroll,107 DUMMY_NATIVE_EVENT,108 renderedTargetID,109 DUMMY_RENDERED_TARGET110 );111};112var onGrantChild;113var onGrantParent;114var onGrantGrandParent;115var existsInExtraction = function(extracted, test) {116 if (Array.isArray(extracted)) {117 for (var i = 0; i < extracted.length; i++) {118 if (test(extracted[i])) {119 return true;120 }121 }122 } else if (extracted) {123 return test(extracted);124 }125 return false;126};127/**128 * Helper validators.129 */130function assertGrantEvent(id, extracted) {131 var test = function(abstractEvent) {132 return abstractEvent instanceof AbstractEvent &&133 abstractEvent.type === responderAbstractEventTypes.responderGrant &&134 abstractEvent.abstractTargetID === id;135 };136 expect(ResponderEventPlugin.getResponderID()).toBe(id);137 expect(existsInExtraction(extracted, test)).toBe(true);138}139function assertResponderMoveEvent(id, extracted) {140 var test = function(abstractEvent) {141 return abstractEvent instanceof AbstractEvent &&142 abstractEvent.type === responderAbstractEventTypes.responderMove &&143 abstractEvent.abstractTargetID === id;144 };145 expect(ResponderEventPlugin.getResponderID()).toBe(id);146 expect(existsInExtraction(extracted, test)).toBe(true);147}148function assertTerminateEvent(id, extracted) {149 var test = function(abstractEvent) {150 return abstractEvent instanceof AbstractEvent &&151 abstractEvent.type === responderAbstractEventTypes.responderTerminate &&152 abstractEvent.abstractTargetID === id;153 };154 expect(ResponderEventPlugin.getResponderID()).not.toBe(id);155 expect(existsInExtraction(extracted, test)).toBe(true);156}157function assertRelease(id, extracted) {158 var test = function(abstractEvent) {159 return abstractEvent instanceof AbstractEvent &&160 abstractEvent.type === responderAbstractEventTypes.responderRelease &&161 abstractEvent.abstractTargetID === id;162 };163 expect(ResponderEventPlugin.getResponderID()).toBe(null);164 expect(existsInExtraction(extracted, test)).toBe(true);165}166function assertNothingExtracted(extracted) {167 expect(Array.isArray(extracted)).toBe(false); // No grant events.168 expect(Array.isArray(extracted)).toBeFalsy();169}170/**171 * TODO:172 * - Test that returning false from `responderTerminationRequest` will never173 * cause the responder to be lost.174 * - Automate some of this testing by providing config data - generalize.175 */176describe('ResponderEventPlugin', function() {177 beforeEach(function() {178 require('mock-modules').dumpCache();179 AbstractEvent = require('AbstractEvent');180 CallbackRegistry = require('CallbackRegistry');181 EventConstants = require('EventConstants');182 EventPropagators = require('EventPropagators');183 ReactInstanceHandles = require('ReactInstanceHandles');184 ResponderEventPlugin = require('ResponderEventPlugin');185 EventPropagators.injection.injectInstanceHandle(ReactInstanceHandles);186 // dumpCache, in open-source tests, only resets existing mocks. It does not187 // reset module-state though -- so we need to do this explicitly in the test188 // for now. Once that's no longer the case, we can delete this line.189 CallbackRegistry.__purge();190 topLevelTypes = EventConstants.topLevelTypes;191 responderAbstractEventTypes = ResponderEventPlugin.abstractEventTypes;192 spies = {193 onStartShouldSetResponderChild: function() {},194 onStartShouldSetResponderParent: function() {},195 onStartShouldSetResponderParentCapture: function() {},196 onStartShouldSetResponderGrandParent: function() {},197 onMoveShouldSetResponderParent: function() {},198 onScrollShouldSetResponderParent: function() {}199 };200 onGrantChild = function() {};201 onGrantParent = function() {};202 onGrantGrandParent = function() {};203 });204 it('should not auto-set responder on touch start', function() {205 // Notice we're not registering the startShould* handler.206 var extracted = extractForTouchStart(CHILD_ID);207 assertNothingExtracted(extracted);208 expect(ResponderEventPlugin.getResponderID()).toBe(null);209 });210 it('should not auto-set responder on mouse down', function() {211 // Notice we're not registering the startShould* handler.212 var extracted = extractForMouseDown(CHILD_ID);213 assertNothingExtracted(extracted);214 expect(ResponderEventPlugin.getResponderID()).toBe(null);215 extractForMouseUp(CHILD_ID); // Let up!216 expect(ResponderEventPlugin.getResponderID()).toBe(null);217 // Register `onMoveShould*` handler.218 spyOn(spies, 'onMoveShouldSetResponderParent').andReturn(true);219 onMoveShouldSetResponder(PARENT_ID, spies.onMoveShouldSetResponderParent);220 onResponderGrant(PARENT_ID, onGrantParent);221 // Move mouse while not pressing down222 extracted = extractForMouseMove(CHILD_ID);223 assertNothingExtracted(extracted);224 // Not going to call `onMoveShould`* if not touching.225 expect(spies.onMoveShouldSetResponderParent.callCount).toBe(0);226 expect(ResponderEventPlugin.getResponderID()).toBe(null);227 // Now try the move extraction again, this time while holding down, and not228 // letting up.229 extracted = extractForMouseDown(CHILD_ID);230 assertNothingExtracted(extracted);231 expect(ResponderEventPlugin.getResponderID()).toBe(null);232 // Now moving can set the responder, if pressing down, even if there is no233 // current responder.234 extracted = extractForMouseMove(CHILD_ID);235 expect(spies.onMoveShouldSetResponderParent.callCount).toBe(1);236 expect(ResponderEventPlugin.getResponderID()).toBe(PARENT_ID);237 assertGrantEvent(PARENT_ID, extracted);238 extractForMouseUp(CHILD_ID);239 expect(ResponderEventPlugin.getResponderID()).toBe(null);240 });241 it('should not extract a grant/release event if double start', function() {242 // Return true - we should become the responder.243 var extracted;244 spyOn(spies, 'onStartShouldSetResponderChild').andReturn(true);245 onStartShouldSetResponder(CHILD_ID, spies.onStartShouldSetResponderChild);246 onResponderGrant(CHILD_ID, onGrantChild);247 extracted = extractForTouchStart(CHILD_ID);248 assertGrantEvent(CHILD_ID, extracted);249 expect(spies.onStartShouldSetResponderChild.callCount).toBe(1);250 // Now we do *not* clear out the touch via a simulated touch end. This mocks251 // out an environment that likely will never happen, but could in some odd252 // error state so it's nice to make sure we recover gracefully.253 // extractForTouchEnd(CHILD_ID); // Clear the responder254 extracted = extractForTouchStart(CHILD_ID);255 assertNothingExtracted();256 expect(spies.onStartShouldSetResponderChild.callCount).toBe(2);257 });258 it('should bubble/capture responder on start', function() {259 // Return true - we should become the responder.260 var extracted;261 spyOn(spies, 'onStartShouldSetResponderParent').andReturn(true);262 spyOn(spies, 'onStartShouldSetResponderChild').andReturn(true);263 onStartShouldSetResponder(CHILD_ID, spies.onStartShouldSetResponderChild);264 onStartShouldSetResponder(PARENT_ID, spies.onStartShouldSetResponderParent);265 onResponderGrant(CHILD_ID, onGrantChild);266 onResponderGrant(PARENT_ID, onGrantParent);267 // Nothing extracted if no responder.268 extracted = extractForTouchMove(GRANDPARENT_ID);269 assertNothingExtracted(extracted);270 extracted = extractForTouchStart(CHILD_ID);271 assertGrantEvent(CHILD_ID, extracted);272 expect(spies.onStartShouldSetResponderChild.callCount).toBe(1);273 expect(spies.onStartShouldSetResponderParent.callCount).toBe(0);274 // Even if moving on the grandparent, the child will receive responder moves275 // (This is even true for mouse interactions - which we should absolutely276 // test)277 extracted = extractForTouchMove(GRANDPARENT_ID);278 assertResponderMoveEvent(CHILD_ID, extracted);279 extracted = extractForTouchMove(CHILD_ID); // Test move on child node too.280 assertResponderMoveEvent(CHILD_ID, extracted);281 // Reset the responder - id passed here shouldn't matter:282 // TODO: Test varying the id here.283 extracted = extractForTouchEnd(GRANDPARENT_ID); // Clear the responder284 assertRelease(CHILD_ID, extracted);285 // Now make sure the parent requests responder on capture.286 spyOn(spies, 'onStartShouldSetResponderParentCapture').andReturn(true);287 onStartShouldSetResponder(288 PARENT_ID,289 spies.onStartShouldSetResponderParent,290 true // Capture291 );292 onResponderGrant(PARENT_ID, onGrantGrandParent);293 extracted = extractForTouchStart(PARENT_ID);294 expect(ResponderEventPlugin.getResponderID()).toBe(PARENT_ID);295 assertGrantEvent(PARENT_ID, extracted);296 // Now move on various nodes, ensuring that the responder move is emitted to297 // the parent node.298 extracted = extractForTouchMove(GRANDPARENT_ID);299 assertResponderMoveEvent(PARENT_ID, extracted);300 extracted = extractForTouchMove(CHILD_ID); // Test move on child node too.301 assertResponderMoveEvent(PARENT_ID, extracted);302 // Reset the responder - id passed here shouldn't matter:303 // TODO: Test varying the id here.304 extracted = extractForTouchEnd(GRANDPARENT_ID); // Clear the responder305 assertRelease(PARENT_ID, extracted);306 });307 it('should invoke callback to ask if responder is desired', function() {308 // Return true - we should become the responder.309 spyOn(spies, 'onStartShouldSetResponderChild').andReturn(true);310 onStartShouldSetResponder(CHILD_ID, spies.onStartShouldSetResponderChild);311 var extracted = extractForTouchStart(CHILD_ID);312 assertNothingExtracted(extracted);313 expect(spies.onStartShouldSetResponderChild.callCount).toBe(1);314 expect(ResponderEventPlugin.getResponderID()).toBe(CHILD_ID);315 extractForTouchEnd(CHILD_ID); // Clear the responder316 // Now try returning false - we should not become the responder.317 spies.onStartShouldSetResponderChild.andReturn(false);318 onStartShouldSetResponder(CHILD_ID, spies.onStartShouldSetResponderChild);319 extracted = extractForTouchStart(CHILD_ID);320 assertNothingExtracted(extracted);321 expect(spies.onStartShouldSetResponderChild.callCount).toBe(2);322 expect(ResponderEventPlugin.getResponderID()).toBe(null);323 extractForTouchEnd(CHILD_ID);324 expect(ResponderEventPlugin.getResponderID()).toBe(null); // Still null325 // Same thing as before but return true from "shouldSet".326 spies.onStartShouldSetResponderChild.andReturn(true);327 onStartShouldSetResponder(CHILD_ID, spies.onStartShouldSetResponderChild);328 onResponderGrant(CHILD_ID, onGrantChild);329 extracted = extractForTouchStart(CHILD_ID);330 expect(spies.onStartShouldSetResponderChild.callCount).toBe(3);331 assertGrantEvent(CHILD_ID, extracted);332 extracted = extractForTouchEnd(CHILD_ID); // Clear the responder333 assertRelease(CHILD_ID, extracted);334 });335 it('should give up responder to parent on move iff allowed', function() {336 // Return true - we should become the responder.337 var extracted;338 spyOn(spies, 'onStartShouldSetResponderChild').andReturn(true);339 spyOn(spies, 'onMoveShouldSetResponderParent').andReturn(true);340 onStartShouldSetResponder(CHILD_ID, spies.onStartShouldSetResponderChild);341 onMoveShouldSetResponder(PARENT_ID, spies.onMoveShouldSetResponderParent);342 onResponderGrant(CHILD_ID, onGrantChild);343 onResponderGrant(PARENT_ID, onGrantParent);344 spies.onStartShouldSetResponderChild.andReturn(true);345 onStartShouldSetResponder(CHILD_ID, spies.onStartShouldSetResponderChild);346 extracted = extractForTouchStart(CHILD_ID);347 expect(spies.onStartShouldSetResponderChild.callCount).toBe(1);348 expect(spies.onMoveShouldSetResponderParent.callCount).toBe(0); // none yet349 assertGrantEvent(CHILD_ID, extracted); // Child is the current responder350 extracted = extractForTouchMove(CHILD_ID);351 expect(spies.onMoveShouldSetResponderParent.callCount).toBe(1);352 assertGrantEvent(PARENT_ID, extracted);353 assertTerminateEvent(CHILD_ID, extracted);354 extracted = extractForTouchEnd(CHILD_ID); // Clear the responder355 assertRelease(PARENT_ID, extracted);356 });357 it('should responder move only on direct responder', function() {358 // Return true - we should become the responder.359 spyOn(spies, 'onStartShouldSetResponderChild').andReturn(true);360 onStartShouldSetResponder(CHILD_ID, spies.onStartShouldSetResponderChild);361 var extracted = extractForTouchStart(CHILD_ID);362 assertNothingExtracted(extracted);363 expect(spies.onStartShouldSetResponderChild.callCount).toBe(1);364 expect(ResponderEventPlugin.getResponderID()).toBe(CHILD_ID);365 extractForTouchEnd(CHILD_ID); // Clear the responder366 expect(ResponderEventPlugin.getResponderID()).toBe(null);367 // Now try returning false - we should not become the responder.368 spies.onStartShouldSetResponderChild.andReturn(false);369 onStartShouldSetResponder(CHILD_ID, spies.onStartShouldSetResponderChild);370 extracted = extractForTouchStart(CHILD_ID);371 assertNothingExtracted(extracted);372 expect(spies.onStartShouldSetResponderChild.callCount).toBe(2);373 expect(ResponderEventPlugin.getResponderID()).toBe(null);374 extractForTouchEnd(CHILD_ID); // Clear the responder375 // Same thing as before but return true from "shouldSet".376 spies.onStartShouldSetResponderChild.andReturn(true);377 onStartShouldSetResponder(CHILD_ID, spies.onStartShouldSetResponderChild);378 onResponderGrant(CHILD_ID, onGrantChild);379 extracted = extractForTouchStart(CHILD_ID);380 expect(spies.onStartShouldSetResponderChild.callCount).toBe(3);381 assertGrantEvent(CHILD_ID, extracted);382 extracted = extractForTouchEnd(CHILD_ID); // Clear the responder383 assertRelease(CHILD_ID, extracted);384 });385 it('should give up responder to parent on scroll iff allowed', function() {386 // Return true - we should become the responder.387 var extracted;388 spyOn(spies, 'onStartShouldSetResponderChild').andReturn(true);389 spyOn(spies, 'onMoveShouldSetResponderParent').andReturn(false);390 spyOn(spies, 'onScrollShouldSetResponderParent').andReturn(true);391 onStartShouldSetResponder(CHILD_ID, spies.onStartShouldSetResponderChild);392 onMoveShouldSetResponder(PARENT_ID, spies.onMoveShouldSetResponderParent);393 onScrollShouldSetResponder(394 PARENT_ID,395 spies.onScrollShouldSetResponderParent396 );397 onResponderGrant(CHILD_ID, onGrantChild);398 onResponderGrant(PARENT_ID, onGrantParent);399 spies.onStartShouldSetResponderChild.andReturn(true);400 onStartShouldSetResponder(CHILD_ID, spies.onStartShouldSetResponderChild);401 extracted = extractForTouchStart(CHILD_ID);402 expect(spies.onStartShouldSetResponderChild.callCount).toBe(1);403 expect(spies.onMoveShouldSetResponderParent.callCount).toBe(0); // none yet404 assertGrantEvent(CHILD_ID, extracted); // Child is the current responder405 extracted = extractForTouchMove(CHILD_ID);406 expect(spies.onMoveShouldSetResponderParent.callCount).toBe(1);407 assertNothingExtracted(extracted);408 extracted = extractForScroll(CHILD_ID); // Could have been parent here too.409 expect(spies.onScrollShouldSetResponderParent.callCount).toBe(1);410 assertGrantEvent(PARENT_ID, extracted);411 assertTerminateEvent(CHILD_ID, extracted);412 extracted = extractForTouchEnd(CHILD_ID); // Clear the responder413 assertRelease(PARENT_ID, extracted);414 });...

Full Screen

Full Screen

89ac43ResponderEventPlugin.js

Source:89ac43ResponderEventPlugin.js Github

copy

Full Screen

1'use strict';2var EventPluginUtils = require('EventPluginUtils');3var EventPropagators = require('EventPropagators');4var ReactTreeTraversal = require('ReactTreeTraversal');5var ResponderSyntheticEvent = require('ResponderSyntheticEvent');6var ResponderTouchHistoryStore = require('ResponderTouchHistoryStore');7var accumulate = require('accumulate');8var isStartish = EventPluginUtils.isStartish;9var isMoveish = EventPluginUtils.isMoveish;10var isEndish = EventPluginUtils.isEndish;11var executeDirectDispatch = EventPluginUtils.executeDirectDispatch;12var hasDispatches = EventPluginUtils.hasDispatches;13var executeDispatchesInOrderStopAtTrue = EventPluginUtils.executeDispatchesInOrderStopAtTrue;14var responderInst = null;15var trackedTouchCount = 0;16var previousActiveTouches = 0;17var changeResponder = function changeResponder(nextResponderInst, blockHostResponder) {18 var oldResponderInst = responderInst;19 responderInst = nextResponderInst;20 if (ResponderEventPlugin.GlobalResponderHandler !== null) {21 ResponderEventPlugin.GlobalResponderHandler.onChange(oldResponderInst, nextResponderInst, blockHostResponder);22 }23};24var eventTypes = {25 startShouldSetResponder: {26 phasedRegistrationNames: {27 bubbled: 'onStartShouldSetResponder',28 captured: 'onStartShouldSetResponderCapture'29 }30 },31 scrollShouldSetResponder: {32 phasedRegistrationNames: {33 bubbled: 'onScrollShouldSetResponder',34 captured: 'onScrollShouldSetResponderCapture'35 }36 },37 selectionChangeShouldSetResponder: {38 phasedRegistrationNames: {39 bubbled: 'onSelectionChangeShouldSetResponder',40 captured: 'onSelectionChangeShouldSetResponderCapture'41 }42 },43 moveShouldSetResponder: {44 phasedRegistrationNames: {45 bubbled: 'onMoveShouldSetResponder',46 captured: 'onMoveShouldSetResponderCapture'47 }48 },49 responderStart: { registrationName: 'onResponderStart' },50 responderMove: { registrationName: 'onResponderMove' },51 responderEnd: { registrationName: 'onResponderEnd' },52 responderRelease: { registrationName: 'onResponderRelease' },53 responderTerminationRequest: {54 registrationName: 'onResponderTerminationRequest'55 },56 responderGrant: { registrationName: 'onResponderGrant' },57 responderReject: { registrationName: 'onResponderReject' },58 responderTerminate: { registrationName: 'onResponderTerminate' }59};60function setResponderAndExtractTransfer(topLevelType, targetInst, nativeEvent, nativeEventTarget) {61 var shouldSetEventType = isStartish(topLevelType) ? eventTypes.startShouldSetResponder : isMoveish(topLevelType) ? eventTypes.moveShouldSetResponder : topLevelType === 'topSelectionChange' ? eventTypes.selectionChangeShouldSetResponder : eventTypes.scrollShouldSetResponder;62 var bubbleShouldSetFrom = !responderInst ? targetInst : ReactTreeTraversal.getLowestCommonAncestor(responderInst, targetInst);63 var skipOverBubbleShouldSetFrom = bubbleShouldSetFrom === responderInst;64 var shouldSetEvent = ResponderSyntheticEvent.getPooled(shouldSetEventType, bubbleShouldSetFrom, nativeEvent, nativeEventTarget);65 shouldSetEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;66 if (skipOverBubbleShouldSetFrom) {67 EventPropagators.accumulateTwoPhaseDispatchesSkipTarget(shouldSetEvent);68 } else {69 EventPropagators.accumulateTwoPhaseDispatches(shouldSetEvent);70 }71 var wantsResponderInst = executeDispatchesInOrderStopAtTrue(shouldSetEvent);72 if (!shouldSetEvent.isPersistent()) {73 shouldSetEvent.constructor.release(shouldSetEvent);74 }75 if (!wantsResponderInst || wantsResponderInst === responderInst) {76 return null;77 }78 var extracted;79 var grantEvent = ResponderSyntheticEvent.getPooled(eventTypes.responderGrant, wantsResponderInst, nativeEvent, nativeEventTarget);80 grantEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;81 EventPropagators.accumulateDirectDispatches(grantEvent);82 var blockHostResponder = executeDirectDispatch(grantEvent) === true;83 if (responderInst) {84 var terminationRequestEvent = ResponderSyntheticEvent.getPooled(eventTypes.responderTerminationRequest, responderInst, nativeEvent, nativeEventTarget);85 terminationRequestEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;86 EventPropagators.accumulateDirectDispatches(terminationRequestEvent);87 var shouldSwitch = !hasDispatches(terminationRequestEvent) || executeDirectDispatch(terminationRequestEvent);88 if (!terminationRequestEvent.isPersistent()) {89 terminationRequestEvent.constructor.release(terminationRequestEvent);90 }91 if (shouldSwitch) {92 var terminateEvent = ResponderSyntheticEvent.getPooled(eventTypes.responderTerminate, responderInst, nativeEvent, nativeEventTarget);93 terminateEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;94 EventPropagators.accumulateDirectDispatches(terminateEvent);95 extracted = accumulate(extracted, [grantEvent, terminateEvent]);96 changeResponder(wantsResponderInst, blockHostResponder);97 } else {98 var rejectEvent = ResponderSyntheticEvent.getPooled(eventTypes.responderReject, wantsResponderInst, nativeEvent, nativeEventTarget);99 rejectEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;100 EventPropagators.accumulateDirectDispatches(rejectEvent);101 extracted = accumulate(extracted, rejectEvent);102 }103 } else {104 extracted = accumulate(extracted, grantEvent);105 changeResponder(wantsResponderInst, blockHostResponder);106 }107 return extracted;108}109function canTriggerTransfer(topLevelType, topLevelInst, nativeEvent) {110 return topLevelInst && (topLevelType === 'topScroll' && !nativeEvent.responderIgnoreScroll || trackedTouchCount > 0 && topLevelType === 'topSelectionChange' || isStartish(topLevelType) || isMoveish(topLevelType));111}112function noResponderTouches(nativeEvent) {113 var touches = nativeEvent.touches;114 if (!touches || touches.length === 0) {115 return true;116 }117 for (var i = 0; i < touches.length; i++) {118 var activeTouch = touches[i];119 var target = activeTouch.target;120 if (target !== null && target !== undefined && target !== 0) {121 var targetInst = EventPluginUtils.getInstanceFromNode(target);122 if (ReactTreeTraversal.isAncestor(responderInst, targetInst)) {123 return false;124 }125 }126 }127 return true;128}129var ResponderEventPlugin = {130 _getResponder: function _getResponder() {131 return responderInst;132 },133 eventTypes: eventTypes,134 extractEvents: function extractEvents(topLevelType, targetInst, nativeEvent, nativeEventTarget) {135 if (isStartish(topLevelType)) {136 trackedTouchCount += 1;137 } else if (isEndish(topLevelType)) {138 if (trackedTouchCount >= 0) {139 trackedTouchCount -= 1;140 } else {141 console.error('Ended a touch event which was not counted in `trackedTouchCount`.');142 return null;143 }144 }145 ResponderTouchHistoryStore.recordTouchTrack(topLevelType, nativeEvent);146 var extracted = canTriggerTransfer(topLevelType, targetInst, nativeEvent) ? setResponderAndExtractTransfer(topLevelType, targetInst, nativeEvent, nativeEventTarget) : null;147 var isResponderTouchStart = responderInst && isStartish(topLevelType);148 var isResponderTouchMove = responderInst && isMoveish(topLevelType);149 var isResponderTouchEnd = responderInst && isEndish(topLevelType);150 var incrementalTouch = isResponderTouchStart ? eventTypes.responderStart : isResponderTouchMove ? eventTypes.responderMove : isResponderTouchEnd ? eventTypes.responderEnd : null;151 if (incrementalTouch) {152 var gesture = ResponderSyntheticEvent.getPooled(incrementalTouch, responderInst, nativeEvent, nativeEventTarget);153 gesture.touchHistory = ResponderTouchHistoryStore.touchHistory;154 EventPropagators.accumulateDirectDispatches(gesture);155 extracted = accumulate(extracted, gesture);156 }157 var isResponderTerminate = responderInst && topLevelType === 'topTouchCancel';158 var isResponderRelease = responderInst && !isResponderTerminate && isEndish(topLevelType) && noResponderTouches(nativeEvent);159 var finalTouch = isResponderTerminate ? eventTypes.responderTerminate : isResponderRelease ? eventTypes.responderRelease : null;160 if (finalTouch) {161 var finalEvent = ResponderSyntheticEvent.getPooled(finalTouch, responderInst, nativeEvent, nativeEventTarget);162 finalEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;163 EventPropagators.accumulateDirectDispatches(finalEvent);164 extracted = accumulate(extracted, finalEvent);165 changeResponder(null);166 }167 var numberActiveTouches = ResponderTouchHistoryStore.touchHistory.numberActiveTouches;168 if (ResponderEventPlugin.GlobalInteractionHandler && numberActiveTouches !== previousActiveTouches) {169 ResponderEventPlugin.GlobalInteractionHandler.onChange(numberActiveTouches);170 }171 previousActiveTouches = numberActiveTouches;172 return extracted;173 },174 GlobalResponderHandler: null,175 GlobalInteractionHandler: null,176 injection: {177 injectGlobalResponderHandler: function injectGlobalResponderHandler(GlobalResponderHandler) {178 ResponderEventPlugin.GlobalResponderHandler = GlobalResponderHandler;179 },180 injectGlobalInteractionHandler: function injectGlobalInteractionHandler(GlobalInteractionHandler) {181 ResponderEventPlugin.GlobalInteractionHandler = GlobalInteractionHandler;182 }183 }184};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const wptools = require('wptools');2let page = wptools.page('Albert Einstein');3page.get((err, resp) => {4 console.log(resp);5});6const wptools = require('wptools');7let page = wptools.page('Albert Einstein');8page.get((err, resp) => {9 console.log(resp);10});11const wptools = require('wptools');12let page = wptools.page('Albert Einstein');13page.image((err, resp) => {14 console.log(resp);15});16const wptools = require('wptools');17let page = wptools.page('Albert Einstein');18page.infobox((err, resp) => {19 console.log(resp);20});21const wptools = require('wptools');22let page = wptools.page('Albert Einstein');23page.categories((err, resp) => {24 console.log(resp);25});26const wptools = require('wptools');27let page = wptools.page('Albert Einstein');28page.references((err, resp) => {29 console.log(resp);30});31const wptools = require('wptools');32let page = wptools.page('Albert Einstein');33page.coordinates((err, resp) => {34 console.log(resp);35});36const wptools = require('wptools');37let page = wptools.page('Albert Einstein');38page.links((err, resp) => {39 console.log(resp);40});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org','A.12345678901234567890123456789012');3var options = {4};5var url = 'www.google.com';6wpt.runTest(url, options, function(err, data) {7 if (err) return console.error(err);8 console.log('Test status: ' + data.statusText);9 console.log('Test ID: ' + data.data.testId);10 var testId = data.data.testId;11 wpt.getTestResults(testId, function(err, data) {12 if (err) return console.error(err);13 console.log('Test status: ' + data.statusText);14 console.log('Test results: ' + JSON.stringify(data.data));15 });16});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2var responder = wptoolkit.responder;3var path = require('path');4var wp = new wptoolkit({5 theme: path.join(__dirname, 'themes', 'default')6});7wp.get('posts', function(err, data) {8 console.log(data);9 responder.send(data);10});11var index = function(req, res) {12 res.send('Hello World');13};14module.exports = index;15var posts = function(req, res) {16 res.send('Hello World');17};18module.exports = posts;19var pages = function(req, res) {20 res.send('Hello World');21};22module.exports = pages;23var notFound = function(req, res) {24 res.send('Hello World');25};26module.exports = notFound;27var serverError = function(req, res) {28 res.send('Hello World');29};30module.exports = serverError;31var forbidden = function(req, res) {32 res.send('Hello World');33};34module.exports = forbidden;35var unauthorized = function(req, res) {36 res.send('Hello World');37};38module.exports = unauthorized;39var badRequest = function(req, res) {40 res.send('Hello World');41};42module.exports = badRequest;43var methodNotAllowed = function(req, res) {44 res.send('Hello World');45};46module.exports = methodNotAllowed;47var serviceUnavailable = function(req, res) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2 if (err) console.log(err);3 else console.log(data);4});5### wpt.runTest(options, callback)6* `location` - The location to test from (default: `Dulles:Chrome`)7* `runs` - Number of test runs (default: `3`)8* `firstViewOnly` - Only test the first view (default: `false`)9* `video` - Capture video (default: `true`)10* `mobile` - Test on a mobile device (default: `false`)11* `private` - Keep the test private (default: `false`)12* `key` - API key (default: `demo`)13* `f` - Response format (default: `json`)14### wpt.getLocations(callback)15### wpt.getTesters(callback)

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var options = {3};4var wpt = new WebPageTest('www.webpagetest.org', 'A.9e1a0a6f8d6f7b0a0a0a0a0a0a0a0a0a');5 if (err) return console.error(err);6 console.log(data);7 wpt.getTestResults(data.data.testId, function(err, data) {8 if (err) return console.error(err);9 console.log(data);10 });11});12{ [Error: ENOENT, no such file or directory 'C:\Users\user\Documents\projects\wpt\node_modules\webpagetest\lib\http']13 syscall: 'open' }14var wpt = require('webpagetest');15var wpt = require('webpagetest');

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful