@samitouri / QOS-React / commits / a35387c030

Remove keyMirror in ComponentLifeCycle (#7591)

See rationale in https://www.facebook.com/groups/2003630259862046/permalink/2097088000516271/

Christopher Chedeau committed Aug 28, 2016 at 10:30 UTC a35387c030ce6f18f3386f163e42ddacdabd5297
1 file changed +15 -18
src/renderers/shared/stack/reconciler/__tests__/ReactComponentLifeCycle-test.js
+15 -18
@@ -11,8 +11,6 @@
11
12 'use strict';
13
14 -var keyMirror = require('keyMirror');
15 -
14 var React;
15 var ReactDOM;
16 var ReactInstanceMap;
@@ -68,25 +66,24 @@ var POST_WILL_UNMOUNT_STATE = {
66 /**
67 * Every React component is in one of these life cycles.
68 */
71 -var ComponentLifeCycle = keyMirror({
69 +type ComponentLifeCycle =
70 /**
71 * Mounted components have a DOM node representation and are capable of
72 * receiving new props.
73 */
76 - MOUNTED: null,
74 + 'MOUNTED' |
75 /**
76 * Unmounted components are inactive and cannot receive new props.
77 */
80 - UNMOUNTED: null,
81 -});
78 + 'UNMOUNTED';
79
83 -function getLifeCycleState(instance) {
80 +function getLifeCycleState(instance): ComponentLifeCycle {
81 var internalInstance = ReactInstanceMap.get(instance);
82 // Once a component gets mounted, it has an internal instance, once it
83 // gets unmounted, it loses that internal instance.
84 return internalInstance ?
88 - ComponentLifeCycle.MOUNTED :
89 - ComponentLifeCycle.UNMOUNTED;
85 + 'MOUNTED' :
86 + 'UNMOUNTED';
87 }
88
89 /**
@@ -407,30 +404,30 @@ describe('ReactComponentLifeCycle', function() {
404 GET_INIT_STATE_RETURN_VAL
405 );
406 expect(instance._testJournal.lifeCycleAtStartOfGetInitialState)
410 - .toBe(ComponentLifeCycle.UNMOUNTED);
407 + .toBe('UNMOUNTED');
408
409 // componentWillMount
410 expect(instance._testJournal.stateAtStartOfWillMount).toEqual(
411 instance._testJournal.returnedFromGetInitialState
412 );
413 expect(instance._testJournal.lifeCycleAtStartOfWillMount)
417 - .toBe(ComponentLifeCycle.MOUNTED);
414 + .toBe('MOUNTED');
415
416 // componentDidMount
417 expect(instance._testJournal.stateAtStartOfDidMount)
418 .toEqual(DID_MOUNT_STATE);
419 expect(instance._testJournal.lifeCycleAtStartOfDidMount).toBe(
423 - ComponentLifeCycle.MOUNTED
420 + 'MOUNTED'
421 );
422
423 // render
424 expect(instance._testJournal.stateInInitialRender)
425 .toEqual(INIT_RENDER_STATE);
426 expect(instance._testJournal.lifeCycleInInitialRender).toBe(
430 - ComponentLifeCycle.MOUNTED
427 + 'MOUNTED'
428 );
429
433 - expect(getLifeCycleState(instance)).toBe(ComponentLifeCycle.MOUNTED);
430 + expect(getLifeCycleState(instance)).toBe('MOUNTED');
431
432 // Now *update the component*
433 instance.forceUpdate();
@@ -439,10 +436,10 @@ describe('ReactComponentLifeCycle', function() {
436 expect(instance._testJournal.stateInLaterRender)
437 .toEqual(NEXT_RENDER_STATE);
438 expect(instance._testJournal.lifeCycleInLaterRender).toBe(
442 - ComponentLifeCycle.MOUNTED
439 + 'MOUNTED'
440 );
441
445 - expect(getLifeCycleState(instance)).toBe(ComponentLifeCycle.MOUNTED);
442 + expect(getLifeCycleState(instance)).toBe('MOUNTED');
443
444 ReactDOM.unmountComponentAtNode(container);
445
@@ -450,11 +447,11 @@ describe('ReactComponentLifeCycle', function() {
447 .toEqual(WILL_UNMOUNT_STATE);
448 // componentWillUnmount called right before unmount.
449 expect(instance._testJournal.lifeCycleAtStartOfWillUnmount).toBe(
453 - ComponentLifeCycle.MOUNTED
450 + 'MOUNTED'
451 );
452
453 // But the current lifecycle of the component is unmounted.
457 - expect(getLifeCycleState(instance)).toBe(ComponentLifeCycle.UNMOUNTED);
454 + expect(getLifeCycleState(instance)).toBe('UNMOUNTED');
455 expect(instance.state).toEqual(POST_WILL_UNMOUNT_STATE);
456 });
457