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,58 @@
|
|
|
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
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Escape and wrap key so it is safe to use as a reactid
|
|
16
|
+
*
|
|
17
|
+
* @param {string} key to be escaped.
|
|
18
|
+
* @return {string} the escaped key.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
function escape(key) {
|
|
22
|
+
var escapeRegex = /[=:]/g;
|
|
23
|
+
var escaperLookup = {
|
|
24
|
+
'=': '=0',
|
|
25
|
+
':': '=2'
|
|
26
|
+
};
|
|
27
|
+
var escapedString = ('' + key).replace(escapeRegex, function (match) {
|
|
28
|
+
return escaperLookup[match];
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return '$' + escapedString;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Unescape and unwrap key for human-readable display
|
|
36
|
+
*
|
|
37
|
+
* @param {string} key to unescape.
|
|
38
|
+
* @return {string} the unescaped key.
|
|
39
|
+
*/
|
|
40
|
+
function unescape(key) {
|
|
41
|
+
var unescapeRegex = /(=0|=2)/g;
|
|
42
|
+
var unescaperLookup = {
|
|
43
|
+
'=0': '=',
|
|
44
|
+
'=2': ':'
|
|
45
|
+
};
|
|
46
|
+
var keySubstring = key[0] === '.' && key[1] === '$' ? key.substring(2) : key.substring(1);
|
|
47
|
+
|
|
48
|
+
return ('' + keySubstring).replace(unescapeRegex, function (match) {
|
|
49
|
+
return unescaperLookup[match];
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
var KeyEscapeUtils = {
|
|
54
|
+
escape: escape,
|
|
55
|
+
unescape: unescape
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
module.exports = KeyEscapeUtils;
|
|
@@ -0,0 +1,137 @@
|
|
|
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 _prodInvariant = require('./reactProdInvariant');
|
|
14
|
+
|
|
15
|
+
var ReactPropTypesSecret = require('./ReactPropTypesSecret');
|
|
16
|
+
var propTypesFactory = require('prop-types/factory');
|
|
17
|
+
|
|
18
|
+
var React = require('react/lib/React');
|
|
19
|
+
var PropTypes = propTypesFactory(React.isValidElement);
|
|
20
|
+
|
|
21
|
+
var invariant = require('fbjs/lib/invariant');
|
|
22
|
+
var warning = require('fbjs/lib/warning');
|
|
23
|
+
|
|
24
|
+
var hasReadOnlyValue = {
|
|
25
|
+
'button': true,
|
|
26
|
+
'checkbox': true,
|
|
27
|
+
'image': true,
|
|
28
|
+
'hidden': true,
|
|
29
|
+
'radio': true,
|
|
30
|
+
'reset': true,
|
|
31
|
+
'submit': true
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
function _assertSingleLink(inputProps) {
|
|
35
|
+
!(inputProps.checkedLink == null || inputProps.valueLink == null) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Cannot provide a checkedLink and a valueLink. If you want to use checkedLink, you probably don\'t want to use valueLink and vice versa.') : _prodInvariant('87') : void 0;
|
|
36
|
+
}
|
|
37
|
+
function _assertValueLink(inputProps) {
|
|
38
|
+
_assertSingleLink(inputProps);
|
|
39
|
+
!(inputProps.value == null && inputProps.onChange == null) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Cannot provide a valueLink and a value or onChange event. If you want to use value or onChange, you probably don\'t want to use valueLink.') : _prodInvariant('88') : void 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function _assertCheckedLink(inputProps) {
|
|
43
|
+
_assertSingleLink(inputProps);
|
|
44
|
+
!(inputProps.checked == null && inputProps.onChange == null) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Cannot provide a checkedLink and a checked property or onChange event. If you want to use checked or onChange, you probably don\'t want to use checkedLink') : _prodInvariant('89') : void 0;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
var propTypes = {
|
|
48
|
+
value: function (props, propName, componentName) {
|
|
49
|
+
if (!props[propName] || hasReadOnlyValue[props.type] || props.onChange || props.readOnly || props.disabled) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
return new Error('You provided a `value` prop to a form field without an ' + '`onChange` handler. This will render a read-only field. If ' + 'the field should be mutable use `defaultValue`. Otherwise, ' + 'set either `onChange` or `readOnly`.');
|
|
53
|
+
},
|
|
54
|
+
checked: function (props, propName, componentName) {
|
|
55
|
+
if (!props[propName] || props.onChange || props.readOnly || props.disabled) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
return new Error('You provided a `checked` prop to a form field without an ' + '`onChange` handler. This will render a read-only field. If ' + 'the field should be mutable use `defaultChecked`. Otherwise, ' + 'set either `onChange` or `readOnly`.');
|
|
59
|
+
},
|
|
60
|
+
onChange: PropTypes.func
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
var loggedTypeFailures = {};
|
|
64
|
+
function getDeclarationErrorAddendum(owner) {
|
|
65
|
+
if (owner) {
|
|
66
|
+
var name = owner.getName();
|
|
67
|
+
if (name) {
|
|
68
|
+
return ' Check the render method of `' + name + '`.';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return '';
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Provide a linked `value` attribute for controlled forms. You should not use
|
|
76
|
+
* this outside of the ReactDOM controlled form components.
|
|
77
|
+
*/
|
|
78
|
+
var LinkedValueUtils = {
|
|
79
|
+
checkPropTypes: function (tagName, props, owner) {
|
|
80
|
+
for (var propName in propTypes) {
|
|
81
|
+
if (propTypes.hasOwnProperty(propName)) {
|
|
82
|
+
var error = propTypes[propName](props, propName, tagName, 'prop', null, ReactPropTypesSecret);
|
|
83
|
+
}
|
|
84
|
+
if (error instanceof Error && !(error.message in loggedTypeFailures)) {
|
|
85
|
+
// Only monitor this failure once because there tends to be a lot of the
|
|
86
|
+
// same error.
|
|
87
|
+
loggedTypeFailures[error.message] = true;
|
|
88
|
+
|
|
89
|
+
var addendum = getDeclarationErrorAddendum(owner);
|
|
90
|
+
process.env.NODE_ENV !== 'production' ? warning(false, 'Failed form propType: %s%s', error.message, addendum) : void 0;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @param {object} inputProps Props for form component
|
|
97
|
+
* @return {*} current value of the input either from value prop or link.
|
|
98
|
+
*/
|
|
99
|
+
getValue: function (inputProps) {
|
|
100
|
+
if (inputProps.valueLink) {
|
|
101
|
+
_assertValueLink(inputProps);
|
|
102
|
+
return inputProps.valueLink.value;
|
|
103
|
+
}
|
|
104
|
+
return inputProps.value;
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @param {object} inputProps Props for form component
|
|
109
|
+
* @return {*} current checked status of the input either from checked prop
|
|
110
|
+
* or link.
|
|
111
|
+
*/
|
|
112
|
+
getChecked: function (inputProps) {
|
|
113
|
+
if (inputProps.checkedLink) {
|
|
114
|
+
_assertCheckedLink(inputProps);
|
|
115
|
+
return inputProps.checkedLink.value;
|
|
116
|
+
}
|
|
117
|
+
return inputProps.checked;
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @param {object} inputProps Props for form component
|
|
122
|
+
* @param {SyntheticEvent} event change event to handle
|
|
123
|
+
*/
|
|
124
|
+
executeOnChange: function (inputProps, event) {
|
|
125
|
+
if (inputProps.valueLink) {
|
|
126
|
+
_assertValueLink(inputProps);
|
|
127
|
+
return inputProps.valueLink.requestChange(event.target.value);
|
|
128
|
+
} else if (inputProps.checkedLink) {
|
|
129
|
+
_assertCheckedLink(inputProps);
|
|
130
|
+
return inputProps.checkedLink.requestChange(event.target.checked);
|
|
131
|
+
} else if (inputProps.onChange) {
|
|
132
|
+
return inputProps.onChange.call(undefined, event);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
module.exports = LinkedValueUtils;
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
|
|
12
|
+
'use strict';
|
|
@@ -0,0 +1,111 @@
|
|
|
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
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
var _prodInvariant = require('./reactProdInvariant');
|
|
15
|
+
|
|
16
|
+
var invariant = require('fbjs/lib/invariant');
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Static poolers. Several custom versions for each potential number of
|
|
20
|
+
* arguments. A completely generic pooler is easy to implement, but would
|
|
21
|
+
* require accessing the `arguments` object. In each of these, `this` refers to
|
|
22
|
+
* the Class itself, not an instance. If any others are needed, simply add them
|
|
23
|
+
* here, or in their own files.
|
|
24
|
+
*/
|
|
25
|
+
var oneArgumentPooler = function (copyFieldsFrom) {
|
|
26
|
+
var Klass = this;
|
|
27
|
+
if (Klass.instancePool.length) {
|
|
28
|
+
var instance = Klass.instancePool.pop();
|
|
29
|
+
Klass.call(instance, copyFieldsFrom);
|
|
30
|
+
return instance;
|
|
31
|
+
} else {
|
|
32
|
+
return new Klass(copyFieldsFrom);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
var twoArgumentPooler = function (a1, a2) {
|
|
37
|
+
var Klass = this;
|
|
38
|
+
if (Klass.instancePool.length) {
|
|
39
|
+
var instance = Klass.instancePool.pop();
|
|
40
|
+
Klass.call(instance, a1, a2);
|
|
41
|
+
return instance;
|
|
42
|
+
} else {
|
|
43
|
+
return new Klass(a1, a2);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
var threeArgumentPooler = function (a1, a2, a3) {
|
|
48
|
+
var Klass = this;
|
|
49
|
+
if (Klass.instancePool.length) {
|
|
50
|
+
var instance = Klass.instancePool.pop();
|
|
51
|
+
Klass.call(instance, a1, a2, a3);
|
|
52
|
+
return instance;
|
|
53
|
+
} else {
|
|
54
|
+
return new Klass(a1, a2, a3);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
var fourArgumentPooler = function (a1, a2, a3, a4) {
|
|
59
|
+
var Klass = this;
|
|
60
|
+
if (Klass.instancePool.length) {
|
|
61
|
+
var instance = Klass.instancePool.pop();
|
|
62
|
+
Klass.call(instance, a1, a2, a3, a4);
|
|
63
|
+
return instance;
|
|
64
|
+
} else {
|
|
65
|
+
return new Klass(a1, a2, a3, a4);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
var standardReleaser = function (instance) {
|
|
70
|
+
var Klass = this;
|
|
71
|
+
!(instance instanceof Klass) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Trying to release an instance into a pool of a different type.') : _prodInvariant('25') : void 0;
|
|
72
|
+
instance.destructor();
|
|
73
|
+
if (Klass.instancePool.length < Klass.poolSize) {
|
|
74
|
+
Klass.instancePool.push(instance);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
var DEFAULT_POOL_SIZE = 10;
|
|
79
|
+
var DEFAULT_POOLER = oneArgumentPooler;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Augments `CopyConstructor` to be a poolable class, augmenting only the class
|
|
83
|
+
* itself (statically) not adding any prototypical fields. Any CopyConstructor
|
|
84
|
+
* you give this may have a `poolSize` property, and will look for a
|
|
85
|
+
* prototypical `destructor` on instances.
|
|
86
|
+
*
|
|
87
|
+
* @param {Function} CopyConstructor Constructor that can be used to reset.
|
|
88
|
+
* @param {Function} pooler Customizable pooler.
|
|
89
|
+
*/
|
|
90
|
+
var addPoolingTo = function (CopyConstructor, pooler) {
|
|
91
|
+
// Casting as any so that flow ignores the actual implementation and trusts
|
|
92
|
+
// it to match the type we declared
|
|
93
|
+
var NewKlass = CopyConstructor;
|
|
94
|
+
NewKlass.instancePool = [];
|
|
95
|
+
NewKlass.getPooled = pooler || DEFAULT_POOLER;
|
|
96
|
+
if (!NewKlass.poolSize) {
|
|
97
|
+
NewKlass.poolSize = DEFAULT_POOL_SIZE;
|
|
98
|
+
}
|
|
99
|
+
NewKlass.release = standardReleaser;
|
|
100
|
+
return NewKlass;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
var PooledClass = {
|
|
104
|
+
addPoolingTo: addPoolingTo,
|
|
105
|
+
oneArgumentPooler: oneArgumentPooler,
|
|
106
|
+
twoArgumentPooler: twoArgumentPooler,
|
|
107
|
+
threeArgumentPooler: threeArgumentPooler,
|
|
108
|
+
fourArgumentPooler: fourArgumentPooler
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
module.exports = PooledClass;
|
|
@@ -0,0 +1,327 @@
|
|
|
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 _assign = require('object-assign');
|
|
14
|
+
|
|
15
|
+
var EventPluginRegistry = require('./EventPluginRegistry');
|
|
16
|
+
var ReactEventEmitterMixin = require('./ReactEventEmitterMixin');
|
|
17
|
+
var ViewportMetrics = require('./ViewportMetrics');
|
|
18
|
+
|
|
19
|
+
var getVendorPrefixedEventName = require('./getVendorPrefixedEventName');
|
|
20
|
+
var isEventSupported = require('./isEventSupported');
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Summary of `ReactBrowserEventEmitter` event handling:
|
|
24
|
+
*
|
|
25
|
+
* - Top-level delegation is used to trap most native browser events. This
|
|
26
|
+
* may only occur in the main thread and is the responsibility of
|
|
27
|
+
* ReactEventListener, which is injected and can therefore support pluggable
|
|
28
|
+
* event sources. This is the only work that occurs in the main thread.
|
|
29
|
+
*
|
|
30
|
+
* - We normalize and de-duplicate events to account for browser quirks. This
|
|
31
|
+
* may be done in the worker thread.
|
|
32
|
+
*
|
|
33
|
+
* - Forward these native events (with the associated top-level type used to
|
|
34
|
+
* trap it) to `EventPluginHub`, which in turn will ask plugins if they want
|
|
35
|
+
* to extract any synthetic events.
|
|
36
|
+
*
|
|
37
|
+
* - The `EventPluginHub` will then process each event by annotating them with
|
|
38
|
+
* "dispatches", a sequence of listeners and IDs that care about that event.
|
|
39
|
+
*
|
|
40
|
+
* - The `EventPluginHub` then dispatches the events.
|
|
41
|
+
*
|
|
42
|
+
* Overview of React and the event system:
|
|
43
|
+
*
|
|
44
|
+
* +------------+ .
|
|
45
|
+
* | DOM | .
|
|
46
|
+
* +------------+ .
|
|
47
|
+
* | .
|
|
48
|
+
* v .
|
|
49
|
+
* +------------+ .
|
|
50
|
+
* | ReactEvent | .
|
|
51
|
+
* | Listener | .
|
|
52
|
+
* +------------+ . +-----------+
|
|
53
|
+
* | . +--------+|SimpleEvent|
|
|
54
|
+
* | . | |Plugin |
|
|
55
|
+
* +-----|------+ . v +-----------+
|
|
56
|
+
* | | | . +--------------+ +------------+
|
|
57
|
+
* | +-----------.--->|EventPluginHub| | Event |
|
|
58
|
+
* | | . | | +-----------+ | Propagators|
|
|
59
|
+
* | ReactEvent | . | | |TapEvent | |------------|
|
|
60
|
+
* | Emitter | . | |<---+|Plugin | |other plugin|
|
|
61
|
+
* | | . | | +-----------+ | utilities |
|
|
62
|
+
* | +-----------.--->| | +------------+
|
|
63
|
+
* | | | . +--------------+
|
|
64
|
+
* +-----|------+ . ^ +-----------+
|
|
65
|
+
* | . | |Enter/Leave|
|
|
66
|
+
* + . +-------+|Plugin |
|
|
67
|
+
* +-------------+ . +-----------+
|
|
68
|
+
* | application | .
|
|
69
|
+
* |-------------| .
|
|
70
|
+
* | | .
|
|
71
|
+
* | | .
|
|
72
|
+
* +-------------+ .
|
|
73
|
+
* .
|
|
74
|
+
* React Core . General Purpose Event Plugin System
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
var hasEventPageXY;
|
|
78
|
+
var alreadyListeningTo = {};
|
|
79
|
+
var isMonitoringScrollValue = false;
|
|
80
|
+
var reactTopListenersCounter = 0;
|
|
81
|
+
|
|
82
|
+
// For events like 'submit' which don't consistently bubble (which we trap at a
|
|
83
|
+
// lower node than `document`), binding at `document` would cause duplicate
|
|
84
|
+
// events so we don't include them here
|
|
85
|
+
var topEventMapping = {
|
|
86
|
+
topAbort: 'abort',
|
|
87
|
+
topAnimationEnd: getVendorPrefixedEventName('animationend') || 'animationend',
|
|
88
|
+
topAnimationIteration: getVendorPrefixedEventName('animationiteration') || 'animationiteration',
|
|
89
|
+
topAnimationStart: getVendorPrefixedEventName('animationstart') || 'animationstart',
|
|
90
|
+
topBlur: 'blur',
|
|
91
|
+
topCanPlay: 'canplay',
|
|
92
|
+
topCanPlayThrough: 'canplaythrough',
|
|
93
|
+
topChange: 'change',
|
|
94
|
+
topClick: 'click',
|
|
95
|
+
topCompositionEnd: 'compositionend',
|
|
96
|
+
topCompositionStart: 'compositionstart',
|
|
97
|
+
topCompositionUpdate: 'compositionupdate',
|
|
98
|
+
topContextMenu: 'contextmenu',
|
|
99
|
+
topCopy: 'copy',
|
|
100
|
+
topCut: 'cut',
|
|
101
|
+
topDoubleClick: 'dblclick',
|
|
102
|
+
topDrag: 'drag',
|
|
103
|
+
topDragEnd: 'dragend',
|
|
104
|
+
topDragEnter: 'dragenter',
|
|
105
|
+
topDragExit: 'dragexit',
|
|
106
|
+
topDragLeave: 'dragleave',
|
|
107
|
+
topDragOver: 'dragover',
|
|
108
|
+
topDragStart: 'dragstart',
|
|
109
|
+
topDrop: 'drop',
|
|
110
|
+
topDurationChange: 'durationchange',
|
|
111
|
+
topEmptied: 'emptied',
|
|
112
|
+
topEncrypted: 'encrypted',
|
|
113
|
+
topEnded: 'ended',
|
|
114
|
+
topError: 'error',
|
|
115
|
+
topFocus: 'focus',
|
|
116
|
+
topInput: 'input',
|
|
117
|
+
topKeyDown: 'keydown',
|
|
118
|
+
topKeyPress: 'keypress',
|
|
119
|
+
topKeyUp: 'keyup',
|
|
120
|
+
topLoadedData: 'loadeddata',
|
|
121
|
+
topLoadedMetadata: 'loadedmetadata',
|
|
122
|
+
topLoadStart: 'loadstart',
|
|
123
|
+
topMouseDown: 'mousedown',
|
|
124
|
+
topMouseMove: 'mousemove',
|
|
125
|
+
topMouseOut: 'mouseout',
|
|
126
|
+
topMouseOver: 'mouseover',
|
|
127
|
+
topMouseUp: 'mouseup',
|
|
128
|
+
topPaste: 'paste',
|
|
129
|
+
topPause: 'pause',
|
|
130
|
+
topPlay: 'play',
|
|
131
|
+
topPlaying: 'playing',
|
|
132
|
+
topProgress: 'progress',
|
|
133
|
+
topRateChange: 'ratechange',
|
|
134
|
+
topScroll: 'scroll',
|
|
135
|
+
topSeeked: 'seeked',
|
|
136
|
+
topSeeking: 'seeking',
|
|
137
|
+
topSelectionChange: 'selectionchange',
|
|
138
|
+
topStalled: 'stalled',
|
|
139
|
+
topSuspend: 'suspend',
|
|
140
|
+
topTextInput: 'textInput',
|
|
141
|
+
topTimeUpdate: 'timeupdate',
|
|
142
|
+
topTouchCancel: 'touchcancel',
|
|
143
|
+
topTouchEnd: 'touchend',
|
|
144
|
+
topTouchMove: 'touchmove',
|
|
145
|
+
topTouchStart: 'touchstart',
|
|
146
|
+
topTransitionEnd: getVendorPrefixedEventName('transitionend') || 'transitionend',
|
|
147
|
+
topVolumeChange: 'volumechange',
|
|
148
|
+
topWaiting: 'waiting',
|
|
149
|
+
topWheel: 'wheel'
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* To ensure no conflicts with other potential React instances on the page
|
|
154
|
+
*/
|
|
155
|
+
var topListenersIDKey = '_reactListenersID' + String(Math.random()).slice(2);
|
|
156
|
+
|
|
157
|
+
function getListeningForDocument(mountAt) {
|
|
158
|
+
// In IE8, `mountAt` is a host object and doesn't have `hasOwnProperty`
|
|
159
|
+
// directly.
|
|
160
|
+
if (!Object.prototype.hasOwnProperty.call(mountAt, topListenersIDKey)) {
|
|
161
|
+
mountAt[topListenersIDKey] = reactTopListenersCounter++;
|
|
162
|
+
alreadyListeningTo[mountAt[topListenersIDKey]] = {};
|
|
163
|
+
}
|
|
164
|
+
return alreadyListeningTo[mountAt[topListenersIDKey]];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* `ReactBrowserEventEmitter` is used to attach top-level event listeners. For
|
|
169
|
+
* example:
|
|
170
|
+
*
|
|
171
|
+
* EventPluginHub.putListener('myID', 'onClick', myFunction);
|
|
172
|
+
*
|
|
173
|
+
* This would allocate a "registration" of `('onClick', myFunction)` on 'myID'.
|
|
174
|
+
*
|
|
175
|
+
* @internal
|
|
176
|
+
*/
|
|
177
|
+
var ReactBrowserEventEmitter = _assign({}, ReactEventEmitterMixin, {
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Injectable event backend
|
|
181
|
+
*/
|
|
182
|
+
ReactEventListener: null,
|
|
183
|
+
|
|
184
|
+
injection: {
|
|
185
|
+
/**
|
|
186
|
+
* @param {object} ReactEventListener
|
|
187
|
+
*/
|
|
188
|
+
injectReactEventListener: function (ReactEventListener) {
|
|
189
|
+
ReactEventListener.setHandleTopLevel(ReactBrowserEventEmitter.handleTopLevel);
|
|
190
|
+
ReactBrowserEventEmitter.ReactEventListener = ReactEventListener;
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Sets whether or not any created callbacks should be enabled.
|
|
196
|
+
*
|
|
197
|
+
* @param {boolean} enabled True if callbacks should be enabled.
|
|
198
|
+
*/
|
|
199
|
+
setEnabled: function (enabled) {
|
|
200
|
+
if (ReactBrowserEventEmitter.ReactEventListener) {
|
|
201
|
+
ReactBrowserEventEmitter.ReactEventListener.setEnabled(enabled);
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* @return {boolean} True if callbacks are enabled.
|
|
207
|
+
*/
|
|
208
|
+
isEnabled: function () {
|
|
209
|
+
return !!(ReactBrowserEventEmitter.ReactEventListener && ReactBrowserEventEmitter.ReactEventListener.isEnabled());
|
|
210
|
+
},
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* We listen for bubbled touch events on the document object.
|
|
214
|
+
*
|
|
215
|
+
* Firefox v8.01 (and possibly others) exhibited strange behavior when
|
|
216
|
+
* mounting `onmousemove` events at some node that was not the document
|
|
217
|
+
* element. The symptoms were that if your mouse is not moving over something
|
|
218
|
+
* contained within that mount point (for example on the background) the
|
|
219
|
+
* top-level listeners for `onmousemove` won't be called. However, if you
|
|
220
|
+
* register the `mousemove` on the document object, then it will of course
|
|
221
|
+
* catch all `mousemove`s. This along with iOS quirks, justifies restricting
|
|
222
|
+
* top-level listeners to the document object only, at least for these
|
|
223
|
+
* movement types of events and possibly all events.
|
|
224
|
+
*
|
|
225
|
+
* @see http://www.quirksmode.org/blog/archives/2010/09/click_event_del.html
|
|
226
|
+
*
|
|
227
|
+
* Also, `keyup`/`keypress`/`keydown` do not bubble to the window on IE, but
|
|
228
|
+
* they bubble to document.
|
|
229
|
+
*
|
|
230
|
+
* @param {string} registrationName Name of listener (e.g. `onClick`).
|
|
231
|
+
* @param {object} contentDocumentHandle Document which owns the container
|
|
232
|
+
*/
|
|
233
|
+
listenTo: function (registrationName, contentDocumentHandle) {
|
|
234
|
+
var mountAt = contentDocumentHandle;
|
|
235
|
+
var isListening = getListeningForDocument(mountAt);
|
|
236
|
+
var dependencies = EventPluginRegistry.registrationNameDependencies[registrationName];
|
|
237
|
+
|
|
238
|
+
for (var i = 0; i < dependencies.length; i++) {
|
|
239
|
+
var dependency = dependencies[i];
|
|
240
|
+
if (!(isListening.hasOwnProperty(dependency) && isListening[dependency])) {
|
|
241
|
+
if (dependency === 'topWheel') {
|
|
242
|
+
if (isEventSupported('wheel')) {
|
|
243
|
+
ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent('topWheel', 'wheel', mountAt);
|
|
244
|
+
} else if (isEventSupported('mousewheel')) {
|
|
245
|
+
ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent('topWheel', 'mousewheel', mountAt);
|
|
246
|
+
} else {
|
|
247
|
+
// Firefox needs to capture a different mouse scroll event.
|
|
248
|
+
// @see http://www.quirksmode.org/dom/events/tests/scroll.html
|
|
249
|
+
ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent('topWheel', 'DOMMouseScroll', mountAt);
|
|
250
|
+
}
|
|
251
|
+
} else if (dependency === 'topScroll') {
|
|
252
|
+
|
|
253
|
+
if (isEventSupported('scroll', true)) {
|
|
254
|
+
ReactBrowserEventEmitter.ReactEventListener.trapCapturedEvent('topScroll', 'scroll', mountAt);
|
|
255
|
+
} else {
|
|
256
|
+
ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent('topScroll', 'scroll', ReactBrowserEventEmitter.ReactEventListener.WINDOW_HANDLE);
|
|
257
|
+
}
|
|
258
|
+
} else if (dependency === 'topFocus' || dependency === 'topBlur') {
|
|
259
|
+
|
|
260
|
+
if (isEventSupported('focus', true)) {
|
|
261
|
+
ReactBrowserEventEmitter.ReactEventListener.trapCapturedEvent('topFocus', 'focus', mountAt);
|
|
262
|
+
ReactBrowserEventEmitter.ReactEventListener.trapCapturedEvent('topBlur', 'blur', mountAt);
|
|
263
|
+
} else if (isEventSupported('focusin')) {
|
|
264
|
+
// IE has `focusin` and `focusout` events which bubble.
|
|
265
|
+
// @see http://www.quirksmode.org/blog/archives/2008/04/delegating_the.html
|
|
266
|
+
ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent('topFocus', 'focusin', mountAt);
|
|
267
|
+
ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent('topBlur', 'focusout', mountAt);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// to make sure blur and focus event listeners are only attached once
|
|
271
|
+
isListening.topBlur = true;
|
|
272
|
+
isListening.topFocus = true;
|
|
273
|
+
} else if (topEventMapping.hasOwnProperty(dependency)) {
|
|
274
|
+
ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent(dependency, topEventMapping[dependency], mountAt);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
isListening[dependency] = true;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
|
|
282
|
+
trapBubbledEvent: function (topLevelType, handlerBaseName, handle) {
|
|
283
|
+
return ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent(topLevelType, handlerBaseName, handle);
|
|
284
|
+
},
|
|
285
|
+
|
|
286
|
+
trapCapturedEvent: function (topLevelType, handlerBaseName, handle) {
|
|
287
|
+
return ReactBrowserEventEmitter.ReactEventListener.trapCapturedEvent(topLevelType, handlerBaseName, handle);
|
|
288
|
+
},
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Protect against document.createEvent() returning null
|
|
292
|
+
* Some popup blocker extensions appear to do this:
|
|
293
|
+
* https://github.com/facebook/react/issues/6887
|
|
294
|
+
*/
|
|
295
|
+
supportsEventPageXY: function () {
|
|
296
|
+
if (!document.createEvent) {
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
var ev = document.createEvent('MouseEvent');
|
|
300
|
+
return ev != null && 'pageX' in ev;
|
|
301
|
+
},
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Listens to window scroll and resize events. We cache scroll values so that
|
|
305
|
+
* application code can access them without triggering reflows.
|
|
306
|
+
*
|
|
307
|
+
* ViewportMetrics is only used by SyntheticMouse/TouchEvent and only when
|
|
308
|
+
* pageX/pageY isn't supported (legacy browsers).
|
|
309
|
+
*
|
|
310
|
+
* NOTE: Scroll events do not bubble.
|
|
311
|
+
*
|
|
312
|
+
* @see http://www.quirksmode.org/dom/events/scroll.html
|
|
313
|
+
*/
|
|
314
|
+
ensureScrollValueMonitoring: function () {
|
|
315
|
+
if (hasEventPageXY === undefined) {
|
|
316
|
+
hasEventPageXY = ReactBrowserEventEmitter.supportsEventPageXY();
|
|
317
|
+
}
|
|
318
|
+
if (!hasEventPageXY && !isMonitoringScrollValue) {
|
|
319
|
+
var refresh = ViewportMetrics.refreshScrollValues;
|
|
320
|
+
ReactBrowserEventEmitter.ReactEventListener.monitorScrollValue(refresh);
|
|
321
|
+
isMonitoringScrollValue = true;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
module.exports = ReactBrowserEventEmitter;
|