Refactor ResponderEventPlugin to not rely on _rootNodeID
Instead of relying on IDs, we now use instances for everything so this should be reflected by the test. This still has a _rootNodeID to store the listeners which I will remove next.
Sebastian Markbage committed
Oct 27, 2016 at 18:54 UTC
2f8d1689db30a769188f08b79480a1301b736d6f
2 files changed
+85
-178
src/renderers/shared/shared/event/eventPlugins/ResponderEventPlugin.js
+2
-2
@@ -466,8 +466,8 @@ function noResponderTouches(nativeEvent) {
466
var ResponderEventPlugin = {
467
468
/* For unit testing only */
469
- _getResponderID: function() {
470
- return responderInst ? responderInst._rootNodeID : null;
469
+ _getResponder: function() {
470
+ return responderInst;
471
},
472
473
eventTypes: eventTypes,
src/renderers/shared/shared/event/eventPlugins/__tests__/ResponderEventPlugin-test.js
+83
-176
@@ -80,7 +80,7 @@ var _touchConfig = function(
80
changedTouchObjects
81
),
82
topLevelType: topType,
83
- targetInst: idToInstance[targetNodeHandle],
83
+ targetInst: getInstanceFromNode(targetNodeHandle),
84
};
85
};
86
@@ -233,7 +233,7 @@ var registerTestHandlers = function(eventTestConfig, readableIDToID) {
233
}
234
return config.returnVal;
235
}.bind(null, readableID, nodeConfig);
236
- EventPluginHub.putListener(idToInstance[id], registrationName, handler);
236
+ EventPluginHub.putListener(getInstanceFromNode(id), registrationName, handler);
237
}
238
};
239
for (var eventName in eventTestConfig) {
@@ -304,146 +304,53 @@ var run = function(config, hierarchyConfig, nativeEventConfig) {
304
); // +1 for extra ++
305
};
306
307
-var GRANDPARENT_ID = '.0';
308
-var PARENT_ID = '.0.0';
309
-var CHILD_ID = '.0.0.0';
310
-var CHILD_ID2 = '.0.0.1';
307
+var GRANDPARENT_HOST_NODE = { };
308
+var PARENT_HOST_NODE = { };
309
+var CHILD_HOST_NODE = { };
310
+var CHILD_HOST_NODE2 = { };
311
312
-var idToInstance = {};
313
-[GRANDPARENT_ID, PARENT_ID, CHILD_ID, CHILD_ID2].forEach(function(id) {
314
- idToInstance[id] = {_rootNodeID: id};
315
-});
312
+var GRANDPARENT_INST = { _hostParent: null, _rootNodeID: '1', _hostNode: GRANDPARENT_HOST_NODE };
313
+var PARENT_INST = { _hostParent: GRANDPARENT_INST, _rootNodeID: '2', _hostNode: PARENT_HOST_NODE };
314
+var CHILD_INST = { _hostParent: PARENT_INST, _rootNodeID: '3', _hostNode: CHILD_HOST_NODE };
315
+var CHILD_INST2 = { _hostParent: PARENT_INST, _rootNodeID: '4', _hostNode: CHILD_HOST_NODE2 };
316
+
317
+GRANDPARENT_HOST_NODE._reactInstance = GRANDPARENT_INST;
318
+PARENT_HOST_NODE._reactInstance = PARENT_INST;
319
+CHILD_HOST_NODE._reactInstance = CHILD_INST;
320
+CHILD_HOST_NODE2._reactInstance = CHILD_INST2;
321
322
var three = {
318
- grandParent: GRANDPARENT_ID,
319
- parent: PARENT_ID,
320
- child: CHILD_ID,
323
+ grandParent: GRANDPARENT_HOST_NODE,
324
+ parent: PARENT_HOST_NODE,
325
+ child: CHILD_HOST_NODE,
326
};
327
328
var siblings = {
324
- parent: PARENT_ID,
325
- childOne: CHILD_ID,
326
- childTwo: CHILD_ID2,
329
+ parent: PARENT_HOST_NODE,
330
+ childOne: CHILD_HOST_NODE,
331
+ childTwo: CHILD_HOST_NODE2,
332
};
333
329
-describe('ResponderEventPlugin', () => {
330
-
331
- // This test is written against React IDs such as 'root.a.b[10]' but we
332
- // removed those. In order to make those tests still pass with minimum
333
- // surgery, we are inlining the implementation of those IDs here as it
334
- // is the only remaining call site.
335
-
336
- var SEPARATOR = '.';
337
-
338
- function isBoundary(id, index) {
339
- return id.charAt(index) === SEPARATOR || index === id.length;
340
- }
341
-
342
- function isAncestorIDOf(ancestorID, descendantID) {
343
- return (
344
- descendantID.indexOf(ancestorID) === 0 &&
345
- isBoundary(descendantID, ancestorID.length)
346
- );
347
- }
348
-
349
- function getParentID(id) {
350
- return id ? id.substr(0, id.lastIndexOf(SEPARATOR)) : '';
351
- }
352
-
353
- function getNextDescendantID(ancestorID, destinationID) {
354
- if (ancestorID === destinationID) {
355
- return ancestorID;
356
- }
357
- // Skip over the ancestor and the immediate separator. Traverse until we hit
358
- // another separator or we reach the end of `destinationID`.
359
- var start = ancestorID.length + SEPARATOR.length;
360
- var i;
361
- for (i = start; i < destinationID.length; i++) {
362
- if (isBoundary(destinationID, i)) {
363
- break;
364
- }
365
- }
366
- return destinationID.substr(0, i);
367
- }
368
-
369
- function getFirstCommonAncestorID(oneID, twoID) {
370
- var minLength = Math.min(oneID.length, twoID.length);
371
- if (minLength === 0) {
372
- return '';
373
- }
374
- var lastCommonMarkerIndex = 0;
375
- // Use `<=` to traverse until the "EOL" of the shorter string.
376
- for (var i = 0; i <= minLength; i++) {
377
- if (isBoundary(oneID, i) && isBoundary(twoID, i)) {
378
- lastCommonMarkerIndex = i;
379
- } else if (oneID.charAt(i) !== twoID.charAt(i)) {
380
- break;
381
- }
382
- }
383
- return oneID.substr(0, lastCommonMarkerIndex);
384
- }
385
-
386
- function traverseParentPath(start, stop, cb, arg, skipFirst, skipLast) {
387
- var traverseUp = isAncestorIDOf(stop, start);
388
- var traverse = traverseUp ? getParentID : getNextDescendantID;
389
- for (var id = start; /* until break */; id = traverse(id, stop)) {
390
- var ret;
391
- if ((!skipFirst || id !== start) && (!skipLast || id !== stop)) {
392
- ret = cb(id, traverseUp ? 'bubbled': 'captured', arg);
393
- }
394
- if (ret === false || id === stop) {
395
- // Only break //after// visiting `stop`.
396
- break;
397
- }
398
- }
399
- }
334
+function getInstanceFromNode(node) {
335
+ return node._reactInstance;
336
+}
337
401
- function traverseTwoPhase(targetID, cb, arg) {
402
- traverseParentPath('', targetID, cb, arg, true, false);
403
- traverseParentPath(targetID, '', cb, arg, false, true);
404
- }
338
+function getNodeFromInstance(inst) {
339
+ return inst._hostNode;
340
+}
341
406
- // -- end of the React ID implementation
342
+describe('ResponderEventPlugin', () => {
343
344
beforeEach(() => {
345
jest.resetModuleRegistry();
346
411
- // Inline mock
412
- const ReactTreeTraversal = require('ReactTreeTraversal');
413
- Object.assign(ReactTreeTraversal, {
414
- isAncestor: function(a, b) {
415
- return isAncestorIDOf(a._rootNodeID, b._rootNodeID);
416
- },
417
- getLowestCommonAncestor: function(a, b) {
418
- var commonID = getFirstCommonAncestorID(a._rootNodeID, b._rootNodeID);
419
- return idToInstance[commonID] || null;
420
- },
421
- getParentInstance: function(inst) {
422
- var id = inst._rootNodeID;
423
- var parentID = id.substr(0, id.lastIndexOf(SEPARATOR));
424
- return idToInstance[parentID] || null;
425
- },
426
- traverseTwoPhase: function(target, fn, arg) {
427
- traverseTwoPhase(
428
- target._rootNodeID,
429
- function(id, phase) {
430
- fn(idToInstance[id], phase, arg);
431
- }
432
- );
433
- },
434
- });
435
-
347
EventPluginHub = require('EventPluginHub');
348
EventPluginUtils = require('EventPluginUtils');
349
ResponderEventPlugin = require('ResponderEventPlugin');
350
351
EventPluginUtils.injection.injectComponentTree({
441
- getInstanceFromNode: function(id) {
442
- return idToInstance[id];
443
- },
444
- getNodeFromInstance: function(inst) {
445
- return inst._rootNodeID;
446
- },
352
+ getInstanceFromNode,
353
+ getNodeFromInstance,
354
});
355
});
356
@@ -456,12 +363,12 @@ describe('ResponderEventPlugin', () => {
363
config.startShouldSetResponder.bubbled.parent = {order: 4, returnVal: false};
364
config.startShouldSetResponder.bubbled.grandParent = {order: 5, returnVal: false};
365
run(config, three, startConfig(three.child, [three.child], [0]));
459
- expect(ResponderEventPlugin._getResponderID()).toBe(null);
366
+ expect(ResponderEventPlugin._getResponder()).toBe(null);
367
368
// Now no handlers should be called on `touchEnd`.
369
config = oneEventLoopTestConfig(three);
370
run(config, three, endConfig(three.child, [three.child], [0]));
464
- expect(ResponderEventPlugin._getResponderID()).toBe(null);
371
+ expect(ResponderEventPlugin._getResponder()).toBe(null);
372
});
373
374
@@ -477,13 +384,13 @@ describe('ResponderEventPlugin', () => {
384
config.responderGrant.grandParent = {order: 1};
385
config.responderStart.grandParent = {order: 2};
386
run(config, three, startConfig(three.child, [three.child], [0]));
480
- expect(ResponderEventPlugin._getResponderID()).toBe(three.grandParent);
387
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(three.grandParent));
388
389
config = oneEventLoopTestConfig(three);
390
config.responderEnd.grandParent = {order: 0};
391
config.responderRelease.grandParent = {order: 1};
392
run(config, three, endConfig(three.child, [three.child], [0]));
486
- expect(ResponderEventPlugin._getResponderID()).toBe(null);
393
+ expect(ResponderEventPlugin._getResponder()).toBe(null);
394
});
395
396
it('should grant responder parent while capturing', () => {
@@ -493,13 +400,13 @@ describe('ResponderEventPlugin', () => {
400
config.responderGrant.parent = {order: 2};
401
config.responderStart.parent = {order: 3};
402
run(config, three, startConfig(three.child, [three.child], [0]));
496
- expect(ResponderEventPlugin._getResponderID()).toBe(three.parent);
403
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(three.parent));
404
405
config = oneEventLoopTestConfig(three);
406
config.responderEnd.parent = {order: 0};
407
config.responderRelease.parent = {order: 1};
408
run(config, three, endConfig(three.child, [three.child], [0]));
502
- expect(ResponderEventPlugin._getResponderID()).toBe(null);
409
+ expect(ResponderEventPlugin._getResponder()).toBe(null);
410
});
411
412
it('should grant responder child while capturing', () => {
@@ -510,13 +417,13 @@ describe('ResponderEventPlugin', () => {
417
config.responderGrant.child = {order: 3};
418
config.responderStart.child = {order: 4};
419
run(config, three, startConfig(three.child, [three.child], [0]));
513
- expect(ResponderEventPlugin._getResponderID()).toBe(three.child);
420
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(three.child));
421
422
config = oneEventLoopTestConfig(three);
423
config.responderEnd.child = {order: 0};
424
config.responderRelease.child = {order: 1};
425
run(config, three, endConfig(three.child, [three.child], [0]));
519
- expect(ResponderEventPlugin._getResponderID()).toBe(null);
426
+ expect(ResponderEventPlugin._getResponder()).toBe(null);
427
});
428
429
it('should grant responder child while bubbling', () => {
@@ -528,13 +435,13 @@ describe('ResponderEventPlugin', () => {
435
config.responderGrant.child = {order: 4};
436
config.responderStart.child = {order: 5};
437
run(config, three, startConfig(three.child, [three.child], [0]));
531
- expect(ResponderEventPlugin._getResponderID()).toBe(three.child);
438
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(three.child));
439
440
config = oneEventLoopTestConfig(three);
441
config.responderEnd.child = {order: 0};
442
config.responderRelease.child = {order: 1};
443
run(config, three, endConfig(three.child, [three.child], [0]));
537
- expect(ResponderEventPlugin._getResponderID()).toBe(null);
444
+ expect(ResponderEventPlugin._getResponder()).toBe(null);
445
});
446
447
it('should grant responder parent while bubbling', () => {
@@ -547,13 +454,13 @@ describe('ResponderEventPlugin', () => {
454
config.responderGrant.parent = {order: 5};
455
config.responderStart.parent = {order: 6};
456
run(config, three, startConfig(three.child, [three.child], [0]));
550
- expect(ResponderEventPlugin._getResponderID()).toBe(three.parent);
457
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(three.parent));
458
459
config = oneEventLoopTestConfig(three);
460
config.responderEnd.parent = {order: 0};
461
config.responderRelease.parent = {order: 1};
462
run(config, three, endConfig(three.child, [three.child], [0]));
556
- expect(ResponderEventPlugin._getResponderID()).toBe(null);
463
+ expect(ResponderEventPlugin._getResponder()).toBe(null);
464
});
465
466
it('should grant responder grandParent while bubbling', () => {
@@ -567,13 +474,13 @@ describe('ResponderEventPlugin', () => {
474
config.responderGrant.grandParent = {order: 6};
475
config.responderStart.grandParent = {order: 7};
476
run(config, three, startConfig(three.child, [three.child], [0]));
570
- expect(ResponderEventPlugin._getResponderID()).toBe(three.grandParent);
477
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(three.grandParent));
478
479
config = oneEventLoopTestConfig(three);
480
config.responderEnd.grandParent = {order: 0};
481
config.responderRelease.grandParent = {order: 1};
482
run(config, three, endConfig(three.child, [three.child], [0]));
576
- expect(ResponderEventPlugin._getResponderID()).toBe(null);
483
+ expect(ResponderEventPlugin._getResponder()).toBe(null);
484
});
485
486
@@ -599,13 +506,13 @@ describe('ResponderEventPlugin', () => {
506
config.responderGrant.grandParent = {order: 1};
507
config.responderMove.grandParent = {order: 2};
508
run(config, three, moveConfig(three.child, [three.child], [0]));
602
- expect(ResponderEventPlugin._getResponderID()).toBe(three.grandParent);
509
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(three.grandParent));
510
511
config = oneEventLoopTestConfig(three);
512
config.responderEnd.grandParent = {order: 0};
513
config.responderRelease.grandParent = {order: 1};
514
run(config, three, endConfig(three.child, [three.child], [0]));
608
- expect(ResponderEventPlugin._getResponderID()).toBe(null);
515
+ expect(ResponderEventPlugin._getResponder()).toBe(null);
516
});
517
518
it('should grant responder parent while capturing move', () => {
@@ -625,13 +532,13 @@ describe('ResponderEventPlugin', () => {
532
config.responderGrant.parent = {order: 2};
533
config.responderMove.parent = {order: 3};
534
run(config, three, moveConfig(three.child, [three.child], [0]));
628
- expect(ResponderEventPlugin._getResponderID()).toBe(three.parent);
535
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(three.parent));
536
537
config = oneEventLoopTestConfig(three);
538
config.responderEnd.parent = {order: 0};
539
config.responderRelease.parent = {order: 1};
540
run(config, three, endConfig(three.child, [three.child], [0]));
634
- expect(ResponderEventPlugin._getResponderID()).toBe(null);
541
+ expect(ResponderEventPlugin._getResponder()).toBe(null);
542
});
543
544
it('should grant responder child while capturing move', () => {
@@ -652,13 +559,13 @@ describe('ResponderEventPlugin', () => {
559
config.responderGrant.child = {order: 3};
560
config.responderMove.child = {order: 4};
561
run(config, three, moveConfig(three.child, [three.child], [0]));
655
- expect(ResponderEventPlugin._getResponderID()).toBe(three.child);
562
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(three.child));
563
564
config = oneEventLoopTestConfig(three);
565
config.responderEnd.child = {order: 0};
566
config.responderRelease.child = {order: 1};
567
run(config, three, endConfig(three.child, [three.child], [0]));
661
- expect(ResponderEventPlugin._getResponderID()).toBe(null);
568
+ expect(ResponderEventPlugin._getResponder()).toBe(null);
569
});
570
571
it('should grant responder child while bubbling move', () => {
@@ -680,13 +587,13 @@ describe('ResponderEventPlugin', () => {
587
config.responderGrant.child = {order: 4};
588
config.responderMove.child = {order: 5};
589
run(config, three, moveConfig(three.child, [three.child], [0]));
683
- expect(ResponderEventPlugin._getResponderID()).toBe(three.child);
590
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(three.child));
591
592
config = oneEventLoopTestConfig(three);
593
config.responderEnd.child = {order: 0};
594
config.responderRelease.child = {order: 1};
595
run(config, three, endConfig(three.child, [three.child], [0]));
689
- expect(ResponderEventPlugin._getResponderID()).toBe(null);
596
+ expect(ResponderEventPlugin._getResponder()).toBe(null);
597
});
598
599
it('should grant responder parent while bubbling move', () => {
@@ -709,13 +616,13 @@ describe('ResponderEventPlugin', () => {
616
config.responderGrant.parent = {order: 5};
617
config.responderMove.parent = {order: 6};
618
run(config, three, moveConfig(three.child, [three.child], [0]));
712
- expect(ResponderEventPlugin._getResponderID()).toBe(three.parent);
619
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(three.parent));
620
621
config = oneEventLoopTestConfig(three);
622
config.responderEnd.parent = {order: 0};
623
config.responderRelease.parent = {order: 1};
624
run(config, three, endConfig(three.child, [three.child], [0]));
718
- expect(ResponderEventPlugin._getResponderID()).toBe(null);
625
+ expect(ResponderEventPlugin._getResponder()).toBe(null);
626
});
627
628
it('should grant responder grandParent while bubbling move', () => {
@@ -739,13 +646,13 @@ describe('ResponderEventPlugin', () => {
646
config.responderGrant.grandParent = {order: 6};
647
config.responderMove.grandParent = {order: 7};
648
run(config, three, moveConfig(three.child, [three.child], [0]));
742
- expect(ResponderEventPlugin._getResponderID()).toBe(three.grandParent);
649
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(three.grandParent));
650
651
config = oneEventLoopTestConfig(three);
652
config.responderEnd.grandParent = {order: 0};
653
config.responderRelease.grandParent = {order: 1};
654
run(config, three, endConfig(three.child, [three.child], [0]));
748
- expect(ResponderEventPlugin._getResponderID()).toBe(null);
655
+ expect(ResponderEventPlugin._getResponder()).toBe(null);
656
});
657
658
@@ -761,7 +668,7 @@ describe('ResponderEventPlugin', () => {
668
config.responderGrant.parent = {order: 2};
669
config.responderStart.parent = {order: 3};
670
run(config, three, startConfig(three.child, [three.child], [0]));
764
- expect(ResponderEventPlugin._getResponderID()).toBe(three.parent);
671
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(three.parent));
672
673
// While `parent` is still responder, we create new handlers that verify
674
// the ordering of propagation, restarting the count at `0`.
@@ -771,13 +678,13 @@ describe('ResponderEventPlugin', () => {
678
config.startShouldSetResponder.bubbled.grandParent = {order: 1, returnVal: false};
679
config.responderStart.parent = {order: 2};
680
run(config, three, startConfig(three.child, [three.child], [0]));
774
- expect(ResponderEventPlugin._getResponderID()).toBe(three.parent);
681
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(three.parent));
682
683
config = oneEventLoopTestConfig(three);
684
config.responderEnd.parent = {order: 0};
685
config.responderRelease.parent = {order: 1};
686
run(config, three, endConfig(three.child, [three.child], [0]));
780
- expect(ResponderEventPlugin._getResponderID()).toBe(null);
687
+ expect(ResponderEventPlugin._getResponder()).toBe(null);
688
});
689
690
it('should bubble negotiation to first common ancestor of responder then transfer', () => {
@@ -787,7 +694,7 @@ describe('ResponderEventPlugin', () => {
694
config.responderGrant.parent = {order: 2};
695
config.responderStart.parent = {order: 3};
696
run(config, three, startConfig(three.child, [three.child], [0]));
790
- expect(ResponderEventPlugin._getResponderID()).toBe(three.parent);
697
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(three.parent));
698
699
config = oneEventLoopTestConfig(three);
700
@@ -798,19 +705,19 @@ describe('ResponderEventPlugin', () => {
705
config.responderTerminate.parent = {order: 3};
706
config.responderStart.grandParent = {order: 4};
707
run(config, three, startConfig(three.child, [three.child, three.child], [1]));
801
- expect(ResponderEventPlugin._getResponderID()).toBe(three.grandParent);
708
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(three.grandParent));
709
710
config = oneEventLoopTestConfig(three);
711
config.responderEnd.grandParent = {order: 0};
712
// one remains\ /one ended \
713
run(config, three, endConfig(three.child, [three.child, three.child], [1]));
807
- expect(ResponderEventPlugin._getResponderID()).toBe(three.grandParent);
714
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(three.grandParent));
715
716
config = oneEventLoopTestConfig(three);
717
config.responderEnd.grandParent = {order: 0};
718
config.responderRelease.grandParent = {order: 1};
719
run(config, three, endConfig(three.child, [three.child], [0]));
813
- expect(ResponderEventPlugin._getResponderID()).toBe(null);
720
+ expect(ResponderEventPlugin._getResponder()).toBe(null);
721
});
722
723
/**
@@ -826,7 +733,7 @@ describe('ResponderEventPlugin', () => {
733
config.startShouldSetResponder.bubbled.grandParent = {order: 3, returnVal: false};
734
735
run(config, three, startConfig(three.parent, [three.parent], [0]));
829
- expect(ResponderEventPlugin._getResponderID()).toBe(null);
736
+ expect(ResponderEventPlugin._getResponder()).toBe(null);
737
738
config = oneEventLoopTestConfig(three);
739
@@ -842,7 +749,7 @@ describe('ResponderEventPlugin', () => {
749
config.responderStart.child = {order: 5};
750
// / Two active touches \ /one of them new\
751
run(config, three, startConfig(three.child, [three.parent, three.child], [1]));
845
- expect(ResponderEventPlugin._getResponderID()).toBe(three.child);
752
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(three.child));
753
754
755
// Now we remove the original first touch, keeping the second touch that
@@ -852,7 +759,7 @@ describe('ResponderEventPlugin', () => {
759
config.responderEnd.child = {order: 0};
760
// / one ended\ /one remains \
761
run(config, three, endConfig(three.child, [three.parent, three.child], [0]));
855
- expect(ResponderEventPlugin._getResponderID()).toBe(three.child);
762
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(three.child));
763
764
// Okay, now let's add back that first touch (nothing should change) and
765
// then we'll try peeling back the touches in the opposite order to make
@@ -868,7 +775,7 @@ describe('ResponderEventPlugin', () => {
775
config.responderStart.child = {order: 4};
776
// / Two active touches \ /one of them new\
777
run(config, three, startConfig(three.parent, [three.child, three.parent], [1]));
871
- expect(ResponderEventPlugin._getResponderID()).toBe(three.child);
778
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(three.child));
779
780
781
// Now, move that new touch that had no effect, and did not start within
@@ -883,7 +790,7 @@ describe('ResponderEventPlugin', () => {
790
config.responderMove.child = {order: 4};
791
// / Two active touches \ /one of them moved\
792
run(config, three, moveConfig(three.parent, [three.child, three.parent], [1]));
886
- expect(ResponderEventPlugin._getResponderID()).toBe(three.child);
793
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(three.child));
794
795
796
config = oneEventLoopTestConfig(three);
@@ -891,7 +798,7 @@ describe('ResponderEventPlugin', () => {
798
config.responderRelease.child = {order: 1};
799
// /child end \ /parent remain\
800
run(config, three, endConfig(three.child, [three.child, three.parent], [0]));
894
- expect(ResponderEventPlugin._getResponderID()).toBe(null);
801
+ expect(ResponderEventPlugin._getResponder()).toBe(null);
802
});
803
804
@@ -909,7 +816,7 @@ describe('ResponderEventPlugin', () => {
816
config.responderStart.childOne = {order: 4};
817
818
run(config, siblings, startConfig(siblings.childOne, [siblings.childOne], [0]));
912
- expect(ResponderEventPlugin._getResponderID()).toBe(siblings.childOne);
819
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(siblings.childOne));
820
821
// If the touch target is the sibling item, the negotiation should only
822
// propagate to first common ancestor of current responder and sibling (so
@@ -922,7 +829,7 @@ describe('ResponderEventPlugin', () => {
829
var touchConfig =
830
startConfig(siblings.childTwo, [siblings.childOne, siblings.childTwo], [1]);
831
run(config, siblings, touchConfig);
925
- expect(ResponderEventPlugin._getResponderID()).toBe(siblings.childOne);
832
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(siblings.childOne));
833
834
835
// move childOne
@@ -931,7 +838,7 @@ describe('ResponderEventPlugin', () => {
838
config.moveShouldSetResponder.bubbled.parent = {order: 1, returnVal: false};
839
config.responderMove.childOne = {order: 2};
840
run(config, siblings, moveConfig(siblings.childOne, [siblings.childOne, siblings.childTwo], [0]));
934
- expect(ResponderEventPlugin._getResponderID()).toBe(siblings.childOne);
841
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(siblings.childOne));
842
843
// move childTwo: Only negotiates to `parent`.
844
config = oneEventLoopTestConfig(siblings);
@@ -939,7 +846,7 @@ describe('ResponderEventPlugin', () => {
846
config.moveShouldSetResponder.bubbled.parent = {order: 1, returnVal: false};
847
config.responderMove.childOne = {order: 2};
848
run(config, siblings, moveConfig(siblings.childTwo, [siblings.childOne, siblings.childTwo], [1]));
942
- expect(ResponderEventPlugin._getResponderID()).toBe(siblings.childOne);
849
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(siblings.childOne));
850
851
});
852
@@ -955,7 +862,7 @@ describe('ResponderEventPlugin', () => {
862
config.responderStart.child = {order: 5};
863
864
run(config, three, startConfig(three.child, [three.child], [0]));
958
- expect(ResponderEventPlugin._getResponderID()).toBe(three.child);
865
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(three.child));
866
867
// Suppose parent wants to become responder on move, and is rejected
868
config = oneEventLoopTestConfig(three);
@@ -971,7 +878,7 @@ describe('ResponderEventPlugin', () => {
878
var touchConfig =
879
moveConfig(three.child, [three.child], [0]);
880
run(config, three, touchConfig);
974
- expect(ResponderEventPlugin._getResponderID()).toBe(three.child);
881
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(three.child));
882
883
config = oneEventLoopTestConfig(three);
884
config.startShouldSetResponder.captured.grandParent = {order: 0, returnVal: false};
@@ -986,7 +893,7 @@ describe('ResponderEventPlugin', () => {
893
touchConfig =
894
startConfig(three.child, [three.child, three.child], [1]);
895
run(config, three, touchConfig);
989
- expect(ResponderEventPlugin._getResponderID()).toBe(three.child);
896
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(three.child));
897
898
});
899
@@ -1002,7 +909,7 @@ describe('ResponderEventPlugin', () => {
909
config.responderStart.child = {order: 5};
910
911
run(config, three, startConfig(three.child, [three.child], [0]));
1005
- expect(ResponderEventPlugin._getResponderID()).toBe(three.child);
912
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(three.child));
913
914
// If the touch target is the sibling item, the negotiation should only
915
// propagate to first common ancestor of current responder and sibling (so
@@ -1017,10 +924,10 @@ describe('ResponderEventPlugin', () => {
924
925
run(config, three, {
926
topLevelType: 'topScroll',
1020
- targetInst: idToInstance[three.parent],
927
+ targetInst: getInstanceFromNode(three.parent),
928
nativeEvent: {},
929
});
1023
- expect(ResponderEventPlugin._getResponderID()).toBe(three.child);
930
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(three.child));
931
932
933
// Now lets let the scroll take control this time.
@@ -1034,10 +941,10 @@ describe('ResponderEventPlugin', () => {
941
942
run(config, three, {
943
topLevelType: 'topScroll',
1037
- targetInst: idToInstance[three.parent],
944
+ targetInst: getInstanceFromNode(three.parent),
945
nativeEvent: {},
946
});
1040
- expect(ResponderEventPlugin._getResponderID()).toBe(three.parent);
947
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(three.parent));
948
949
950
});
@@ -1053,7 +960,7 @@ describe('ResponderEventPlugin', () => {
960
config.responderStart.child = {order: 5};
961
962
run(config, three, startConfig(three.child, [three.child], [0]));
1056
- expect(ResponderEventPlugin._getResponderID()).toBe(three.child);
963
+ expect(ResponderEventPlugin._getResponder()).toBe(getInstanceFromNode(three.child));
964
965
config = oneEventLoopTestConfig(three);
966
config.responderEnd.child = {order: 0};
@@ -1066,6 +973,6 @@ describe('ResponderEventPlugin', () => {
973
[0]
974
);
975
run(config, three, nativeEvent);
1069
- expect(ResponderEventPlugin._getResponderID()).toBe(null);
976
+ expect(ResponderEventPlugin._getResponder()).toBe(null);
977
});
978
});