react-test-renderer 15.5.0 → 15.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ReactShallowRenderer.js +6 -0
- package/lib/shallow/ARIADOMPropertyConfig.js +73 -0
- package/lib/shallow/AutoFocusUtils.js +23 -0
- package/lib/shallow/BeforeInputEventPlugin.js +384 -0
- package/lib/shallow/CSSProperty.js +147 -0
- package/lib/shallow/CSSPropertyOperations.js +208 -0
- package/lib/shallow/CallbackQueue.js +118 -0
- package/lib/shallow/ChangeEventPlugin.js +345 -0
- package/lib/shallow/DOMChildrenOperations.js +224 -0
- package/lib/shallow/DOMLazyTree.js +117 -0
- package/lib/shallow/DOMNamespaces.js +19 -0
- package/lib/shallow/DOMProperty.js +209 -0
- package/lib/shallow/DOMPropertyOperations.js +236 -0
- package/lib/shallow/Danger.js +47 -0
- package/lib/shallow/DefaultEventPluginOrder.js +25 -0
- package/lib/shallow/EnterLeaveEventPlugin.js +99 -0
- package/lib/shallow/EventConstants.js +91 -0
- package/lib/shallow/EventPluginHub.js +277 -0
- package/lib/shallow/EventPluginRegistry.js +254 -0
- package/lib/shallow/EventPluginUtils.js +225 -0
- package/lib/shallow/EventPropagators.js +133 -0
- package/lib/shallow/FallbackCompositionState.js +94 -0
- package/lib/shallow/HTMLDOMPropertyConfig.js +235 -0
- package/lib/shallow/KeyEscapeUtils.js +58 -0
- package/lib/shallow/LinkedValueUtils.js +137 -0
- package/lib/shallow/PluginModuleType.js +12 -0
- package/lib/shallow/PooledClass.js +111 -0
- package/lib/shallow/ReactBrowserEventEmitter.js +327 -0
- package/lib/shallow/ReactChildFiber.js +243 -0
- package/lib/shallow/ReactChildReconciler.js +153 -0
- package/lib/shallow/ReactComponentBrowserEnvironment.js +29 -0
- package/lib/shallow/ReactComponentEnvironment.js +45 -0
- package/lib/shallow/ReactCompositeComponent.js +901 -0
- package/lib/shallow/ReactCoroutine.js +80 -0
- package/lib/shallow/ReactDOM.js +110 -0
- package/lib/shallow/ReactDOMComponent.js +1000 -0
- package/lib/shallow/ReactDOMComponentFlags.js +17 -0
- package/lib/shallow/ReactDOMComponentTree.js +194 -0
- package/lib/shallow/ReactDOMContainerInfo.js +32 -0
- package/lib/shallow/ReactDOMEmptyComponent.js +59 -0
- package/lib/shallow/ReactDOMFeatureFlags.js +18 -0
- package/lib/shallow/ReactDOMFiber.js +97 -0
- package/lib/shallow/ReactDOMIDOperations.js +33 -0
- package/lib/shallow/ReactDOMInput.js +284 -0
- package/lib/shallow/ReactDOMInvalidARIAHook.js +92 -0
- package/lib/shallow/ReactDOMNullInputValuePropHook.js +42 -0
- package/lib/shallow/ReactDOMOption.js +122 -0
- package/lib/shallow/ReactDOMSelect.js +199 -0
- package/lib/shallow/ReactDOMSelection.js +211 -0
- package/lib/shallow/ReactDOMServer.js +25 -0
- package/lib/shallow/ReactDOMTextComponent.js +163 -0
- package/lib/shallow/ReactDOMTextarea.js +159 -0
- package/lib/shallow/ReactDOMTreeTraversal.js +135 -0
- package/lib/shallow/ReactDOMUnknownPropertyHook.js +111 -0
- package/lib/shallow/ReactDebugTool.js +358 -0
- package/lib/shallow/ReactDefaultBatchingStrategy.js +67 -0
- package/lib/shallow/ReactDefaultInjection.js +85 -0
- package/lib/shallow/ReactElementSymbol.js +19 -0
- package/lib/shallow/ReactEmptyComponent.js +29 -0
- package/lib/shallow/ReactErrorUtils.js +75 -0
- package/lib/shallow/ReactEventEmitterMixin.js +32 -0
- package/lib/shallow/ReactEventListener.js +154 -0
- package/lib/shallow/ReactFeatureFlags.js +21 -0
- package/lib/shallow/ReactFiber.js +190 -0
- package/lib/shallow/ReactFiberBeginWork.js +380 -0
- package/lib/shallow/ReactFiberCommitWork.js +78 -0
- package/lib/shallow/ReactFiberCompleteWork.js +208 -0
- package/lib/shallow/ReactFiberReconciler.js +64 -0
- package/lib/shallow/ReactFiberRoot.js +29 -0
- package/lib/shallow/ReactFiberScheduler.js +331 -0
- package/lib/shallow/ReactFiberUpdateQueue.js +77 -0
- package/lib/shallow/ReactHostComponent.js +67 -0
- package/lib/shallow/ReactHostOperationHistoryHook.js +33 -0
- package/lib/shallow/ReactInjection.js +33 -0
- package/lib/shallow/ReactInputSelection.js +123 -0
- package/lib/shallow/ReactInstanceMap.js +47 -0
- package/lib/shallow/ReactInstanceType.js +12 -0
- package/lib/shallow/ReactInstrumentation.js +23 -0
- package/lib/shallow/ReactInvalidSetStateWarningHook.js +36 -0
- package/lib/shallow/ReactMarkupChecksum.js +49 -0
- package/lib/shallow/ReactMount.js +537 -0
- package/lib/shallow/ReactMultiChild.js +449 -0
- package/lib/shallow/ReactMultiChildUpdateTypes.js +18 -0
- package/lib/shallow/ReactNodeTypes.js +39 -0
- package/lib/shallow/ReactOwner.js +93 -0
- package/lib/shallow/ReactPerf.js +500 -0
- package/lib/shallow/ReactPriorityLevel.js +20 -0
- package/lib/shallow/ReactPropTypeLocationNames.js +24 -0
- package/lib/shallow/ReactPropTypeLocations.js +12 -0
- package/lib/shallow/ReactPropTypesSecret.js +16 -0
- package/lib/shallow/ReactReconcileTransaction.js +177 -0
- package/lib/shallow/ReactReconciler.js +167 -0
- package/lib/shallow/ReactRef.js +88 -0
- package/lib/shallow/ReactReifiedYield.js +30 -0
- package/lib/shallow/ReactServerBatchingStrategy.js +21 -0
- package/lib/shallow/ReactServerRendering.js +89 -0
- package/lib/shallow/ReactServerRenderingTransaction.js +89 -0
- package/lib/shallow/ReactServerUpdateQueue.js +138 -0
- package/lib/shallow/ReactShallowRenderer.js +150 -0
- package/lib/shallow/ReactSimpleEmptyComponent.js +36 -0
- package/lib/shallow/ReactSyntheticEventType.js +14 -0
- package/lib/shallow/ReactTestEmptyComponent.js +36 -0
- package/lib/shallow/ReactTestMount.js +131 -0
- package/lib/shallow/ReactTestReconcileTransaction.js +128 -0
- package/lib/shallow/ReactTestRenderer.js +139 -0
- package/lib/shallow/ReactTestTextComponent.js +40 -0
- package/lib/shallow/ReactTypeOfWork.js +23 -0
- package/lib/shallow/ReactTypes.js +12 -0
- package/lib/shallow/ReactUpdateQueue.js +235 -0
- package/lib/shallow/ReactUpdates.js +250 -0
- package/lib/shallow/ReactVersion.js +13 -0
- package/lib/shallow/ResponderEventPlugin.js +507 -0
- package/lib/shallow/ResponderSyntheticEvent.js +38 -0
- package/lib/shallow/ResponderTouchHistoryStore.js +183 -0
- package/lib/shallow/SVGDOMPropertyConfig.js +301 -0
- package/lib/shallow/SelectEventPlugin.js +190 -0
- package/lib/shallow/SimpleEventPlugin.js +227 -0
- package/lib/shallow/SyntheticAnimationEvent.js +38 -0
- package/lib/shallow/SyntheticClipboardEvent.js +37 -0
- package/lib/shallow/SyntheticCompositionEvent.js +35 -0
- package/lib/shallow/SyntheticDragEvent.js +35 -0
- package/lib/shallow/SyntheticEvent.js +267 -0
- package/lib/shallow/SyntheticFocusEvent.js +35 -0
- package/lib/shallow/SyntheticInputEvent.js +36 -0
- package/lib/shallow/SyntheticKeyboardEvent.js +83 -0
- package/lib/shallow/SyntheticMouseEvent.js +71 -0
- package/lib/shallow/SyntheticTouchEvent.js +44 -0
- package/lib/shallow/SyntheticTransitionEvent.js +38 -0
- package/lib/shallow/SyntheticUIEvent.js +58 -0
- package/lib/shallow/SyntheticWheelEvent.js +53 -0
- package/lib/shallow/TapEventPlugin.js +115 -0
- package/lib/shallow/TouchHistoryMath.js +98 -0
- package/lib/shallow/Transaction.js +224 -0
- package/lib/shallow/ViewportMetrics.js +26 -0
- package/lib/shallow/accumulate.js +45 -0
- package/lib/shallow/accumulateInto.js +57 -0
- package/lib/shallow/adler32.js +43 -0
- package/lib/shallow/canDefineProperty.js +25 -0
- package/lib/shallow/checkReactTypeSpec.js +86 -0
- package/lib/shallow/createMicrosoftUnsafeLocalFunction.js +31 -0
- package/lib/shallow/dangerousStyleValue.js +78 -0
- package/lib/shallow/deprecated.js +56 -0
- package/lib/shallow/escapeTextContentForBrowser.js +122 -0
- package/lib/shallow/findDOMNode.js +59 -0
- package/lib/shallow/flattenChildren.js +75 -0
- package/lib/shallow/forEachAccumulated.js +30 -0
- package/lib/shallow/getEventCharCode.js +49 -0
- package/lib/shallow/getEventKey.js +101 -0
- package/lib/shallow/getEventModifierState.js +42 -0
- package/lib/shallow/getEventTarget.js +34 -0
- package/lib/shallow/getHostComponentFromComposite.js +29 -0
- package/lib/shallow/getIteratorFn.js +40 -0
- package/lib/shallow/getNodeForCharacterOffset.js +73 -0
- package/lib/shallow/getTextContentAccessor.js +32 -0
- package/lib/shallow/getVendorPrefixedEventName.js +100 -0
- package/lib/shallow/instantiateReactComponent.js +128 -0
- package/lib/shallow/isEventSupported.js +59 -0
- package/lib/shallow/isTextInputElement.js +50 -0
- package/lib/shallow/quoteAttributeValueForBrowser.js +25 -0
- package/lib/shallow/reactProdInvariant.js +38 -0
- package/lib/shallow/renderSubtreeIntoContainer.js +15 -0
- package/lib/shallow/setInnerHTML.js +97 -0
- package/lib/shallow/setTextContent.js +51 -0
- package/lib/shallow/shouldUpdateReactComponent.js +41 -0
- package/lib/shallow/traverseAllChildren.js +175 -0
- package/lib/shallow/validateDOMNesting.js +376 -0
- package/package.json +1 -1
- package/shallow.js +1 -1
|
@@ -0,0 +1,123 @@
|
|
|
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 the
|
|
6
|
+
* LICENSE file in the root directory of this source tree. An additional grant
|
|
7
|
+
* of patent rights can be found in the PATENTS file in the same directory.
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
var ReactDOMSelection = require('./ReactDOMSelection');
|
|
14
|
+
|
|
15
|
+
var containsNode = require('fbjs/lib/containsNode');
|
|
16
|
+
var focusNode = require('fbjs/lib/focusNode');
|
|
17
|
+
var getActiveElement = require('fbjs/lib/getActiveElement');
|
|
18
|
+
|
|
19
|
+
function isInDocument(node) {
|
|
20
|
+
return containsNode(document.documentElement, node);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @ReactInputSelection: React input selection module. Based on Selection.js,
|
|
25
|
+
* but modified to be suitable for react and has a couple of bug fixes (doesn't
|
|
26
|
+
* assume buttons have range selections allowed).
|
|
27
|
+
* Input selection module for React.
|
|
28
|
+
*/
|
|
29
|
+
var ReactInputSelection = {
|
|
30
|
+
|
|
31
|
+
hasSelectionCapabilities: function (elem) {
|
|
32
|
+
var nodeName = elem && elem.nodeName && elem.nodeName.toLowerCase();
|
|
33
|
+
return nodeName && (nodeName === 'input' && elem.type === 'text' || nodeName === 'textarea' || elem.contentEditable === 'true');
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
getSelectionInformation: function () {
|
|
37
|
+
var focusedElem = getActiveElement();
|
|
38
|
+
return {
|
|
39
|
+
focusedElem: focusedElem,
|
|
40
|
+
selectionRange: ReactInputSelection.hasSelectionCapabilities(focusedElem) ? ReactInputSelection.getSelection(focusedElem) : null
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @restoreSelection: If any selection information was potentially lost,
|
|
46
|
+
* restore it. This is useful when performing operations that could remove dom
|
|
47
|
+
* nodes and place them back in, resulting in focus being lost.
|
|
48
|
+
*/
|
|
49
|
+
restoreSelection: function (priorSelectionInformation) {
|
|
50
|
+
var curFocusedElem = getActiveElement();
|
|
51
|
+
var priorFocusedElem = priorSelectionInformation.focusedElem;
|
|
52
|
+
var priorSelectionRange = priorSelectionInformation.selectionRange;
|
|
53
|
+
if (curFocusedElem !== priorFocusedElem && isInDocument(priorFocusedElem)) {
|
|
54
|
+
if (ReactInputSelection.hasSelectionCapabilities(priorFocusedElem)) {
|
|
55
|
+
ReactInputSelection.setSelection(priorFocusedElem, priorSelectionRange);
|
|
56
|
+
}
|
|
57
|
+
focusNode(priorFocusedElem);
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @getSelection: Gets the selection bounds of a focused textarea, input or
|
|
63
|
+
* contentEditable node.
|
|
64
|
+
* -@input: Look up selection bounds of this input
|
|
65
|
+
* -@return {start: selectionStart, end: selectionEnd}
|
|
66
|
+
*/
|
|
67
|
+
getSelection: function (input) {
|
|
68
|
+
var selection;
|
|
69
|
+
|
|
70
|
+
if ('selectionStart' in input) {
|
|
71
|
+
// Modern browser with input or textarea.
|
|
72
|
+
selection = {
|
|
73
|
+
start: input.selectionStart,
|
|
74
|
+
end: input.selectionEnd
|
|
75
|
+
};
|
|
76
|
+
} else if (document.selection && input.nodeName && input.nodeName.toLowerCase() === 'input') {
|
|
77
|
+
// IE8 input.
|
|
78
|
+
var range = document.selection.createRange();
|
|
79
|
+
// There can only be one selection per document in IE, so it must
|
|
80
|
+
// be in our element.
|
|
81
|
+
if (range.parentElement() === input) {
|
|
82
|
+
selection = {
|
|
83
|
+
start: -range.moveStart('character', -input.value.length),
|
|
84
|
+
end: -range.moveEnd('character', -input.value.length)
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
} else {
|
|
88
|
+
// Content editable or old IE textarea.
|
|
89
|
+
selection = ReactDOMSelection.getOffsets(input);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return selection || { start: 0, end: 0 };
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @setSelection: Sets the selection bounds of a textarea or input and focuses
|
|
97
|
+
* the input.
|
|
98
|
+
* -@input Set selection bounds of this input or textarea
|
|
99
|
+
* -@offsets Object of same form that is returned from get*
|
|
100
|
+
*/
|
|
101
|
+
setSelection: function (input, offsets) {
|
|
102
|
+
var start = offsets.start;
|
|
103
|
+
var end = offsets.end;
|
|
104
|
+
if (end === undefined) {
|
|
105
|
+
end = start;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if ('selectionStart' in input) {
|
|
109
|
+
input.selectionStart = start;
|
|
110
|
+
input.selectionEnd = Math.min(end, input.value.length);
|
|
111
|
+
} else if (document.selection && input.nodeName && input.nodeName.toLowerCase() === 'input') {
|
|
112
|
+
var range = input.createTextRange();
|
|
113
|
+
range.collapse(true);
|
|
114
|
+
range.moveStart('character', start);
|
|
115
|
+
range.moveEnd('character', end - start);
|
|
116
|
+
range.select();
|
|
117
|
+
} else {
|
|
118
|
+
ReactDOMSelection.setOffsets(input, offsets);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
module.exports = ReactInputSelection;
|
|
@@ -0,0 +1,47 @@
|
|
|
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 the
|
|
6
|
+
* LICENSE file in the root directory of this source tree. An additional grant
|
|
7
|
+
* of patent rights can be found in the PATENTS file in the same directory.
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* `ReactInstanceMap` maintains a mapping from a public facing stateful
|
|
15
|
+
* instance (key) and the internal representation (value). This allows public
|
|
16
|
+
* methods to accept the user facing instance as an argument and map them back
|
|
17
|
+
* to internal methods.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
// TODO: Replace this with ES6: var ReactInstanceMap = new Map();
|
|
21
|
+
|
|
22
|
+
var ReactInstanceMap = {
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* This API should be called `delete` but we'd have to make sure to always
|
|
26
|
+
* transform these to strings for IE support. When this transform is fully
|
|
27
|
+
* supported we can rename it.
|
|
28
|
+
*/
|
|
29
|
+
remove: function (key) {
|
|
30
|
+
key._reactInternalInstance = undefined;
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
get: function (key) {
|
|
34
|
+
return key._reactInternalInstance;
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
has: function (key) {
|
|
38
|
+
return key._reactInternalInstance !== undefined;
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
set: function (key, value) {
|
|
42
|
+
key._reactInternalInstance = value;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
module.exports = ReactInstanceMap;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2016-present, Facebook, Inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the BSD-style license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree. An additional grant
|
|
7
|
+
* of patent rights can be found in the PATENTS file in the same directory.
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2016-present, Facebook, Inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the BSD-style license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree. An additional grant
|
|
7
|
+
* of patent rights can be found in the PATENTS file in the same directory.
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
// Trust the developer to only use ReactInstrumentation with a __DEV__ check
|
|
15
|
+
|
|
16
|
+
var debugTool = null;
|
|
17
|
+
|
|
18
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
19
|
+
var ReactDebugTool = require('./ReactDebugTool');
|
|
20
|
+
debugTool = ReactDebugTool;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = { debugTool: debugTool };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2016-present, Facebook, Inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the BSD-style license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree. An additional grant
|
|
7
|
+
* of patent rights can be found in the PATENTS file in the same directory.
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
var warning = require('fbjs/lib/warning');
|
|
15
|
+
|
|
16
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
17
|
+
var processingChildContext = false;
|
|
18
|
+
|
|
19
|
+
var warnInvalidSetState = function () {
|
|
20
|
+
process.env.NODE_ENV !== 'production' ? warning(!processingChildContext, 'setState(...): Cannot call setState() inside getChildContext()') : void 0;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var ReactInvalidSetStateWarningHook = {
|
|
25
|
+
onBeginProcessingChildContext: function () {
|
|
26
|
+
processingChildContext = true;
|
|
27
|
+
},
|
|
28
|
+
onEndProcessingChildContext: function () {
|
|
29
|
+
processingChildContext = false;
|
|
30
|
+
},
|
|
31
|
+
onSetState: function () {
|
|
32
|
+
warnInvalidSetState();
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
module.exports = ReactInvalidSetStateWarningHook;
|
|
@@ -0,0 +1,49 @@
|
|
|
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 the
|
|
6
|
+
* LICENSE file in the root directory of this source tree. An additional grant
|
|
7
|
+
* of patent rights can be found in the PATENTS file in the same directory.
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
var adler32 = require('./adler32');
|
|
14
|
+
|
|
15
|
+
var TAG_END = /\/?>/;
|
|
16
|
+
var COMMENT_START = /^<\!\-\-/;
|
|
17
|
+
|
|
18
|
+
var ReactMarkupChecksum = {
|
|
19
|
+
CHECKSUM_ATTR_NAME: 'data-react-checksum',
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {string} markup Markup string
|
|
23
|
+
* @return {string} Markup string with checksum attribute attached
|
|
24
|
+
*/
|
|
25
|
+
addChecksumToMarkup: function (markup) {
|
|
26
|
+
var checksum = adler32(markup);
|
|
27
|
+
|
|
28
|
+
// Add checksum (handle both parent tags, comments and self-closing tags)
|
|
29
|
+
if (COMMENT_START.test(markup)) {
|
|
30
|
+
return markup;
|
|
31
|
+
} else {
|
|
32
|
+
return markup.replace(TAG_END, ' ' + ReactMarkupChecksum.CHECKSUM_ATTR_NAME + '="' + checksum + '"$&');
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {string} markup to use
|
|
38
|
+
* @param {DOMElement} element root React element
|
|
39
|
+
* @returns {boolean} whether or not the markup is the same
|
|
40
|
+
*/
|
|
41
|
+
canReuseMarkup: function (markup, element) {
|
|
42
|
+
var existingChecksum = element.getAttribute(ReactMarkupChecksum.CHECKSUM_ATTR_NAME);
|
|
43
|
+
existingChecksum = existingChecksum && parseInt(existingChecksum, 10);
|
|
44
|
+
var markupChecksum = adler32(markup);
|
|
45
|
+
return markupChecksum === existingChecksum;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
module.exports = ReactMarkupChecksum;
|