@samitouri / QOS-React-2 / commits / a869f992a8

Remove helper object from FallbackCompositionState (#13430)

There's no good reason for this to be an object. This refactors it so that we just use three variables instead. We can avoid the property reads/writes and also minify better, since property names don't get mangled but variables do.

Brandon Dail committed Aug 18, 2018 at 08:07 UTC a869f992a88692f9d9a964e20ee7dc844bc7760a
1 file changed +18 -19
packages/react-dom/src/events/FallbackCompositionState.js
+18 -19
@@ -8,7 +8,7 @@
8 import getTextContentAccessor from '../client/getTextContentAccessor';
9
10 /**
11 - * This helper object stores information about text content of a target node,
11 + * These variables store information about text content of a target node,
12 * allowing comparison of content before and after a given event.
13 *
14 * Identify the node where selection currently begins, then observe
@@ -18,31 +18,30 @@ import getTextContentAccessor from '../client/getTextContentAccessor';
18 *
19 *
20 */
21 -const compositionState = {
22 - _root: null,
23 - _startText: null,
24 - _fallbackText: null,
25 -};
21 +
22 +let root = null;
23 +let startText = null;
24 +let fallbackText = null;
25
26 export function initialize(nativeEventTarget) {
28 - compositionState._root = nativeEventTarget;
29 - compositionState._startText = getText();
27 + root = nativeEventTarget;
28 + startText = getText();
29 return true;
30 }
31
32 export function reset() {
34 - compositionState._root = null;
35 - compositionState._startText = null;
36 - compositionState._fallbackText = null;
33 + root = null;
34 + startText = null;
35 + fallbackText = null;
36 }
37
38 export function getData() {
40 - if (compositionState._fallbackText) {
41 - return compositionState._fallbackText;
39 + if (fallbackText) {
40 + return fallbackText;
41 }
42
43 let start;
45 - const startValue = compositionState._startText;
44 + const startValue = startText;
45 const startLength = startValue.length;
46 let end;
47 const endValue = getText();
@@ -62,13 +61,13 @@ export function getData() {
61 }
62
63 const sliceTail = end > 1 ? 1 - end : undefined;
65 - compositionState._fallbackText = endValue.slice(start, sliceTail);
66 - return compositionState._fallbackText;
64 + fallbackText = endValue.slice(start, sliceTail);
65 + return fallbackText;
66 }
67
68 export function getText() {
70 - if ('value' in compositionState._root) {
71 - return compositionState._root.value;
69 + if ('value' in root) {
70 + return root.value;
71 }
73 - return compositionState._root[getTextContentAccessor()];
72 + return root[getTextContentAccessor()];
73 }