react 15.2.0 → 15.3.0-rc.3
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/dist/react-with-addons.js +1572 -1136
- package/dist/react-with-addons.min.js +6 -7
- package/dist/react.js +1495 -1064
- package/dist/react.min.js +6 -6
- package/lib/DOMProperty.js +0 -9
- package/lib/DOMPropertyOperations.js +4 -12
- package/lib/Danger.js +0 -98
- package/lib/EventPluginHub.js +14 -6
- package/lib/HTMLDOMPropertyConfig.js +1 -0
- package/lib/KeyEscapeUtils.js +2 -1
- package/lib/LinkedValueUtils.js +2 -1
- package/lib/NativeMethodsMixin.js +1 -1
- package/lib/PooledClass.js +1 -1
- package/lib/React.js +2 -0
- package/lib/ReactChildReconciler.js +21 -4
- package/lib/ReactChildrenMutationWarningDevtool.js +62 -0
- package/lib/ReactClass.js +7 -0
- package/lib/ReactComponentTreeDevtool.js +0 -5
- package/lib/ReactCompositeComponent.js +94 -33
- package/lib/ReactDOM.js +2 -2
- package/lib/ReactDOMComponent.js +23 -1
- package/lib/ReactDOMDebugTool.js +11 -11
- package/lib/ReactDOMFiber.js +78 -0
- package/lib/ReactDOMInput.js +21 -16
- package/lib/ReactDOMInstrumentation.js +7 -2
- package/lib/ReactDOMNullInputValuePropDevtool.js +43 -0
- package/lib/ReactDOMSelect.js +0 -13
- package/lib/ReactDOMTextarea.js +0 -14
- package/lib/ReactDebugTool.js +95 -85
- package/lib/ReactElement.js +8 -0
- package/lib/ReactFeatureFlags.js +1 -0
- package/lib/ReactInstrumentation.js +7 -2
- package/lib/ReactMount.js +15 -17
- package/lib/ReactMultiChild.js +19 -11
- package/lib/ReactNativeMount.js +2 -13
- package/lib/ReactNativeReconcileTransaction.js +16 -0
- package/lib/ReactNodeTypes.js +1 -0
- package/lib/ReactNoop.js +100 -3
- package/lib/ReactNoopUpdateQueue.js +6 -5
- package/lib/ReactPropTypes.js +28 -14
- package/lib/ReactPropTypesSecret.js +16 -0
- package/lib/ReactPureComponent.js +42 -0
- package/lib/ReactReconcileTransaction.js +16 -0
- package/lib/ReactReconciler.js +2 -4
- package/lib/ReactRef.js +3 -1
- package/lib/ReactServerRendering.js +9 -6
- package/lib/ReactServerRenderingTransaction.js +17 -0
- package/lib/ReactServerUpdateQueue.js +141 -0
- package/lib/ReactTestMount.js +29 -27
- package/lib/ReactTestReconcileTransaction.js +8 -0
- package/lib/ReactTestRenderer.js +11 -0
- package/lib/ReactTestUtils.js +7 -3
- package/lib/ReactTransitionGroup.js +1 -0
- package/lib/ReactUpdateQueue.js +6 -3
- package/lib/ReactUpdates.js +1 -10
- package/lib/ReactVersion.js +1 -1
- package/lib/ResponderEventPlugin.js +1 -1
- package/lib/ResponderTouchHistoryStore.js +97 -95
- package/lib/SVGDOMPropertyConfig.js +2 -0
- package/lib/SimpleEventPlugin.js +10 -6
- package/lib/accumulate.js +14 -14
- package/lib/accumulateInto.js +8 -11
- package/lib/adler32.js +1 -0
- package/lib/checkReactTypeSpec.js +22 -6
- package/lib/deprecated.js +7 -1
- package/lib/flattenChildren.js +24 -8
- package/lib/forEachAccumulated.js +3 -2
- package/lib/getIteratorFn.js +1 -0
- package/lib/instantiateReactComponent.js +8 -7
- package/lib/isTextInputElement.js +11 -1
- package/lib/reactProdInvariant.js +1 -0
- package/lib/traverseAllChildren.js +8 -1
- package/package.json +1 -1
package/lib/ReactTestMount.js
CHANGED
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
*/
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
|
+
var _prodInvariant = require('./reactProdInvariant');
|
|
15
|
+
|
|
14
16
|
var ReactElement = require('./ReactElement');
|
|
15
17
|
var ReactInstrumentation = require('./ReactInstrumentation');
|
|
16
18
|
var ReactReconciler = require('./ReactReconciler');
|
|
@@ -19,6 +21,7 @@ var ReactUpdates = require('./ReactUpdates');
|
|
|
19
21
|
var emptyObject = require('fbjs/lib/emptyObject');
|
|
20
22
|
var getHostComponentFromComposite = require('./getHostComponentFromComposite');
|
|
21
23
|
var instantiateReactComponent = require('./instantiateReactComponent');
|
|
24
|
+
var invariant = require('fbjs/lib/invariant');
|
|
22
25
|
|
|
23
26
|
/**
|
|
24
27
|
* Temporary (?) hack so that we can store all top-level pending updates on
|
|
@@ -69,6 +72,29 @@ var ReactTestInstance = function (component) {
|
|
|
69
72
|
ReactTestInstance.prototype.getInstance = function () {
|
|
70
73
|
return this._component._renderedComponent.getPublicInstance();
|
|
71
74
|
};
|
|
75
|
+
ReactTestInstance.prototype.update = function (nextElement) {
|
|
76
|
+
!this._component ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactTestRenderer: .update() can\'t be called after unmount.') : _prodInvariant('139') : void 0;
|
|
77
|
+
var nextWrappedElement = new ReactElement(TopLevelWrapper, null, null, null, null, null, nextElement);
|
|
78
|
+
var component = this._component;
|
|
79
|
+
ReactUpdates.batchedUpdates(function () {
|
|
80
|
+
var transaction = ReactUpdates.ReactReconcileTransaction.getPooled(true);
|
|
81
|
+
transaction.perform(function () {
|
|
82
|
+
ReactReconciler.receiveComponent(component, nextWrappedElement, transaction, emptyObject);
|
|
83
|
+
});
|
|
84
|
+
ReactUpdates.ReactReconcileTransaction.release(transaction);
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
ReactTestInstance.prototype.unmount = function (nextElement) {
|
|
88
|
+
var component = this._component;
|
|
89
|
+
ReactUpdates.batchedUpdates(function () {
|
|
90
|
+
var transaction = ReactUpdates.ReactReconcileTransaction.getPooled(true);
|
|
91
|
+
transaction.perform(function () {
|
|
92
|
+
ReactReconciler.unmountComponent(component, false);
|
|
93
|
+
});
|
|
94
|
+
ReactUpdates.ReactReconcileTransaction.release(transaction);
|
|
95
|
+
});
|
|
96
|
+
this._component = null;
|
|
97
|
+
};
|
|
72
98
|
ReactTestInstance.prototype.toJSON = function () {
|
|
73
99
|
var inst = getHostComponentFromComposite(this._component);
|
|
74
100
|
return inst.toJSON();
|
|
@@ -78,35 +104,12 @@ ReactTestInstance.prototype.toJSON = function () {
|
|
|
78
104
|
* As soon as `ReactMount` is refactored to not rely on the DOM, we can share
|
|
79
105
|
* code between the two. For now, we'll hard code the ID logic.
|
|
80
106
|
*/
|
|
81
|
-
var
|
|
107
|
+
var ReactTestMount = {
|
|
82
108
|
|
|
83
109
|
render: function (nextElement) {
|
|
84
110
|
var nextWrappedElement = new ReactElement(TopLevelWrapper, null, null, null, null, null, nextElement);
|
|
85
111
|
|
|
86
|
-
|
|
87
|
-
// if (prevComponent) {
|
|
88
|
-
// var prevWrappedElement = prevComponent._currentElement;
|
|
89
|
-
// var prevElement = prevWrappedElement.props;
|
|
90
|
-
// if (shouldUpdateReactComponent(prevElement, nextElement)) {
|
|
91
|
-
// ReactUpdateQueue.enqueueElementInternal(prevComponent, nextWrappedElement);
|
|
92
|
-
// if (callback) {
|
|
93
|
-
// ReactUpdateQueue.enqueueCallbackInternal(prevComponent, callback);
|
|
94
|
-
// }
|
|
95
|
-
// return prevComponent;
|
|
96
|
-
// }
|
|
97
|
-
// }
|
|
98
|
-
|
|
99
|
-
var instance = instantiateReactComponent(nextWrappedElement);
|
|
100
|
-
|
|
101
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
102
|
-
// Mute future events from the top level wrapper.
|
|
103
|
-
// It is an implementation detail that devtools should not know about.
|
|
104
|
-
instance._debugID = 0;
|
|
105
|
-
|
|
106
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
107
|
-
ReactInstrumentation.debugTool.onBeginFlush();
|
|
108
|
-
}
|
|
109
|
-
}
|
|
112
|
+
var instance = instantiateReactComponent(nextWrappedElement, false);
|
|
110
113
|
|
|
111
114
|
// The initial render is synchronous but any updates that happen during
|
|
112
115
|
// rendering, in componentWillMount or componentDidMount, will be batched
|
|
@@ -116,11 +119,10 @@ var ReactHostMount = {
|
|
|
116
119
|
if (process.env.NODE_ENV !== 'production') {
|
|
117
120
|
// The instance here is TopLevelWrapper so we report mount for its child.
|
|
118
121
|
ReactInstrumentation.debugTool.onMountRootComponent(instance._renderedComponent._debugID);
|
|
119
|
-
ReactInstrumentation.debugTool.onEndFlush();
|
|
120
122
|
}
|
|
121
123
|
return new ReactTestInstance(instance);
|
|
122
124
|
}
|
|
123
125
|
|
|
124
126
|
};
|
|
125
127
|
|
|
126
|
-
module.exports =
|
|
128
|
+
module.exports = ReactTestMount;
|
|
@@ -16,6 +16,7 @@ var _assign = require('object-assign');
|
|
|
16
16
|
var CallbackQueue = require('./CallbackQueue');
|
|
17
17
|
var PooledClass = require('./PooledClass');
|
|
18
18
|
var Transaction = require('./Transaction');
|
|
19
|
+
var ReactUpdateQueue = require('./ReactUpdateQueue');
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* Provides a `CallbackQueue` queue for collecting `onDOMReady` callbacks during
|
|
@@ -83,6 +84,13 @@ var Mixin = {
|
|
|
83
84
|
return this.reactMountReady;
|
|
84
85
|
},
|
|
85
86
|
|
|
87
|
+
/**
|
|
88
|
+
* @return {object} The queue to collect React async events.
|
|
89
|
+
*/
|
|
90
|
+
getUpdateQueue: function () {
|
|
91
|
+
return ReactUpdateQueue;
|
|
92
|
+
},
|
|
93
|
+
|
|
86
94
|
/**
|
|
87
95
|
* `PooledClass` looks for this, and will invoke this before allowing this
|
|
88
96
|
* instance to be reused.
|
package/lib/ReactTestRenderer.js
CHANGED
|
@@ -15,6 +15,7 @@ var _assign = require('object-assign');
|
|
|
15
15
|
|
|
16
16
|
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
|
|
17
17
|
|
|
18
|
+
var ReactComponentEnvironment = require('./ReactComponentEnvironment');
|
|
18
19
|
var ReactDefaultBatchingStrategy = require('./ReactDefaultBatchingStrategy');
|
|
19
20
|
var ReactEmptyComponent = require('./ReactEmptyComponent');
|
|
20
21
|
var ReactMultiChild = require('./ReactMultiChild');
|
|
@@ -56,6 +57,11 @@ ReactTestComponent.prototype.receiveComponent = function (nextElement, transacti
|
|
|
56
57
|
this.updateChildren(nextElement.props.children, transaction, context);
|
|
57
58
|
};
|
|
58
59
|
ReactTestComponent.prototype.getHostNode = function () {};
|
|
60
|
+
ReactTestComponent.prototype.getPublicInstance = function () {
|
|
61
|
+
// I can't say this makes a ton of sense but it seems better than throwing.
|
|
62
|
+
// Maybe we'll revise later if someone has a good use case.
|
|
63
|
+
return null;
|
|
64
|
+
};
|
|
59
65
|
ReactTestComponent.prototype.unmountComponent = function () {};
|
|
60
66
|
ReactTestComponent.prototype.toJSON = function () {
|
|
61
67
|
var _currentElement$props = this._currentElement.props;
|
|
@@ -121,6 +127,11 @@ ReactEmptyComponent.injection.injectEmptyComponentFactory(function () {
|
|
|
121
127
|
return new ReactTestEmptyComponent();
|
|
122
128
|
});
|
|
123
129
|
|
|
130
|
+
ReactComponentEnvironment.injection.injectEnvironment({
|
|
131
|
+
processChildrenUpdates: function () {},
|
|
132
|
+
replaceNodeWithMarkup: function () {}
|
|
133
|
+
});
|
|
134
|
+
|
|
124
135
|
var ReactTestRenderer = {
|
|
125
136
|
create: ReactTestMount.render,
|
|
126
137
|
|
package/lib/ReactTestUtils.js
CHANGED
|
@@ -344,9 +344,11 @@ NoopInternalComponent.prototype = {
|
|
|
344
344
|
|
|
345
345
|
var ShallowComponentWrapper = function (element) {
|
|
346
346
|
// TODO: Consolidate with instantiateReactComponent
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
347
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
348
|
+
this._debugID = nextDebugID++;
|
|
349
|
+
var displayName = element.type.displayName || element.type.name || 'Unknown';
|
|
350
|
+
ReactInstrumentation.debugTool.onSetDisplayName(this._debugID, displayName);
|
|
351
|
+
}
|
|
350
352
|
|
|
351
353
|
this.construct(element);
|
|
352
354
|
};
|
|
@@ -424,6 +426,8 @@ function makeSimulator(eventType) {
|
|
|
424
426
|
|
|
425
427
|
var fakeNativeEvent = new Event();
|
|
426
428
|
fakeNativeEvent.target = node;
|
|
429
|
+
fakeNativeEvent.type = eventType.toLowerCase();
|
|
430
|
+
|
|
427
431
|
// We don't use SyntheticEvent.getPooled in order to not have to worry about
|
|
428
432
|
// properly destroying any properties assigned from `eventData` upon release
|
|
429
433
|
var event = new SyntheticEvent(dispatchConfig, ReactDOMComponentTree.getInstanceFromNode(node), fakeNativeEvent, node);
|
|
@@ -236,6 +236,7 @@ var ReactTransitionGroup = React.createClass({
|
|
|
236
236
|
delete props.childFactory;
|
|
237
237
|
delete props.transitionLeaveTimeout;
|
|
238
238
|
delete props.transitionEnterTimeout;
|
|
239
|
+
delete props.transitionAppearTimeout;
|
|
239
240
|
delete props.component;
|
|
240
241
|
|
|
241
242
|
return React.createElement(this.props.component, props, childrenToRender);
|
package/lib/ReactUpdateQueue.js
CHANGED
|
@@ -42,10 +42,11 @@ function getInternalInstanceReadyForUpdate(publicInstance, callerName) {
|
|
|
42
42
|
var internalInstance = ReactInstanceMap.get(publicInstance);
|
|
43
43
|
if (!internalInstance) {
|
|
44
44
|
if (process.env.NODE_ENV !== 'production') {
|
|
45
|
+
var ctor = publicInstance.constructor;
|
|
45
46
|
// Only warn when we have a callerName. Otherwise we should be silent.
|
|
46
47
|
// We're probably calling from enqueueCallback. We don't want to warn
|
|
47
48
|
// there because we already warned for the corresponding lifecycle method.
|
|
48
|
-
process.env.NODE_ENV !== 'production' ? warning(!callerName, '%s(...): Can only update a mounted or mounting component. ' + 'This usually means you called %s() on an unmounted component. ' + 'This is a no-op. Please check the code for the %s component.', callerName, callerName,
|
|
49
|
+
process.env.NODE_ENV !== 'production' ? warning(!callerName, '%s(...): Can only update a mounted or mounting component. ' + 'This usually means you called %s() on an unmounted component. ' + 'This is a no-op. Please check the code for the %s component.', callerName, callerName, ctor && (ctor.displayName || ctor.name) || 'ReactClass') : void 0;
|
|
49
50
|
}
|
|
50
51
|
return null;
|
|
51
52
|
}
|
|
@@ -209,8 +210,10 @@ var ReactUpdateQueue = {
|
|
|
209
210
|
enqueueUpdate(internalInstance);
|
|
210
211
|
},
|
|
211
212
|
|
|
212
|
-
enqueueElementInternal: function (internalInstance,
|
|
213
|
-
internalInstance._pendingElement =
|
|
213
|
+
enqueueElementInternal: function (internalInstance, nextElement, nextContext) {
|
|
214
|
+
internalInstance._pendingElement = nextElement;
|
|
215
|
+
// TODO: introduce _pendingContext instead of setting it directly.
|
|
216
|
+
internalInstance._context = nextContext;
|
|
214
217
|
enqueueUpdate(internalInstance);
|
|
215
218
|
},
|
|
216
219
|
|
package/lib/ReactUpdates.js
CHANGED
|
@@ -17,7 +17,6 @@ var _prodInvariant = require('./reactProdInvariant'),
|
|
|
17
17
|
var CallbackQueue = require('./CallbackQueue');
|
|
18
18
|
var PooledClass = require('./PooledClass');
|
|
19
19
|
var ReactFeatureFlags = require('./ReactFeatureFlags');
|
|
20
|
-
var ReactInstrumentation = require('./ReactInstrumentation');
|
|
21
20
|
var ReactReconciler = require('./ReactReconciler');
|
|
22
21
|
var Transaction = require('./Transaction');
|
|
23
22
|
|
|
@@ -164,10 +163,6 @@ function runBatchedUpdates(transaction) {
|
|
|
164
163
|
}
|
|
165
164
|
|
|
166
165
|
var flushBatchedUpdates = function () {
|
|
167
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
168
|
-
ReactInstrumentation.debugTool.onBeginFlush();
|
|
169
|
-
}
|
|
170
|
-
|
|
171
166
|
// ReactUpdatesFlushTransaction's wrappers will clear the dirtyComponents
|
|
172
167
|
// array and perform any updates enqueued by mount-ready handlers (i.e.,
|
|
173
168
|
// componentDidUpdate) but we need to check here too in order to catch
|
|
@@ -187,10 +182,6 @@ var flushBatchedUpdates = function () {
|
|
|
187
182
|
CallbackQueue.release(queue);
|
|
188
183
|
}
|
|
189
184
|
}
|
|
190
|
-
|
|
191
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
192
|
-
ReactInstrumentation.debugTool.onEndFlush();
|
|
193
|
-
}
|
|
194
185
|
};
|
|
195
186
|
|
|
196
187
|
/**
|
|
@@ -203,7 +194,7 @@ function enqueueUpdate(component) {
|
|
|
203
194
|
// Various parts of our code (such as ReactCompositeComponent's
|
|
204
195
|
// _renderValidatedComponent) assume that calls to render aren't nested;
|
|
205
196
|
// verify that that's the case. (This is called by each top-level update
|
|
206
|
-
// function, like
|
|
197
|
+
// function, like setState, forceUpdate, etc.; creation and
|
|
207
198
|
// destruction of top-level components is guarded in ReactMount.)
|
|
208
199
|
|
|
209
200
|
if (!batchingStrategy.isBatchingUpdates) {
|
package/lib/ReactVersion.js
CHANGED
|
@@ -438,7 +438,7 @@ var ResponderEventPlugin = {
|
|
|
438
438
|
!(trackedTouchCount >= 0) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Ended a touch event which was not counted in trackedTouchCount.') : _prodInvariant('132') : void 0;
|
|
439
439
|
}
|
|
440
440
|
|
|
441
|
-
ResponderTouchHistoryStore.recordTouchTrack(topLevelType, nativeEvent
|
|
441
|
+
ResponderTouchHistoryStore.recordTouchTrack(topLevelType, nativeEvent);
|
|
442
442
|
|
|
443
443
|
var extracted = canTriggerTransfer(topLevelType, targetInst, nativeEvent) ? setResponderAndExtractTransfer(topLevelType, targetInst, nativeEvent, nativeEventTarget) : null;
|
|
444
444
|
// Responder may or may not have transferred on a new touch start/move.
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
8
8
|
*
|
|
9
9
|
* @providesModule ResponderTouchHistoryStore
|
|
10
|
+
*
|
|
10
11
|
*/
|
|
11
12
|
|
|
12
13
|
'use strict';
|
|
@@ -16,30 +17,22 @@ var _prodInvariant = require('./reactProdInvariant');
|
|
|
16
17
|
var EventPluginUtils = require('./EventPluginUtils');
|
|
17
18
|
|
|
18
19
|
var invariant = require('fbjs/lib/invariant');
|
|
20
|
+
var warning = require('fbjs/lib/warning');
|
|
19
21
|
|
|
22
|
+
var isEndish = EventPluginUtils.isEndish;
|
|
20
23
|
var isMoveish = EventPluginUtils.isMoveish;
|
|
21
24
|
var isStartish = EventPluginUtils.isStartish;
|
|
22
|
-
var isEndish = EventPluginUtils.isEndish;
|
|
23
|
-
|
|
24
|
-
var MAX_TOUCH_BANK = 20;
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
28
|
-
* see IDs
|
|
29
|
-
*
|
|
30
|
-
* logic modules so precomputing it is very helpful to do once.
|
|
31
|
-
* Each touch object in `touchBank` is of the following form:
|
|
32
|
-
* { touchActive: boolean,
|
|
33
|
-
* startTimeStamp: number,
|
|
34
|
-
* startPageX: number,
|
|
35
|
-
* startPageY: number,
|
|
36
|
-
* currentPageX: number,
|
|
37
|
-
* currentPageY: number,
|
|
38
|
-
* currentTimeStamp: number
|
|
39
|
-
* }
|
|
27
|
+
* Tracks the position and time of each active touch by `touch.identifier`. We
|
|
28
|
+
* should typically only see IDs in the range of 1-20 because IDs get recycled
|
|
29
|
+
* when touches end and start again.
|
|
40
30
|
*/
|
|
31
|
+
|
|
32
|
+
var MAX_TOUCH_BANK = 20;
|
|
33
|
+
var touchBank = [];
|
|
41
34
|
var touchHistory = {
|
|
42
|
-
touchBank:
|
|
35
|
+
touchBank: touchBank,
|
|
43
36
|
numberActiveTouches: 0,
|
|
44
37
|
// If there is only one active touch, we remember its location. This prevents
|
|
45
38
|
// us having to loop through all of the touches all the time in the most
|
|
@@ -48,24 +41,23 @@ var touchHistory = {
|
|
|
48
41
|
mostRecentTimeStamp: 0
|
|
49
42
|
};
|
|
50
43
|
|
|
51
|
-
|
|
44
|
+
function timestampForTouch(touch) {
|
|
52
45
|
// The legacy internal implementation provides "timeStamp", which has been
|
|
53
46
|
// renamed to "timestamp". Let both work for now while we iron it out
|
|
54
47
|
// TODO (evv): rename timeStamp to timestamp in internal code
|
|
55
48
|
return touch.timeStamp || touch.timestamp;
|
|
56
|
-
}
|
|
49
|
+
}
|
|
57
50
|
|
|
58
51
|
/**
|
|
59
52
|
* TODO: Instead of making gestures recompute filtered velocity, we could
|
|
60
53
|
* include a built in velocity computation that can be reused globally.
|
|
61
|
-
* @param {Touch} touch Native touch object.
|
|
62
54
|
*/
|
|
63
|
-
|
|
55
|
+
function createTouchRecord(touch) {
|
|
64
56
|
return {
|
|
65
57
|
touchActive: true,
|
|
66
|
-
startTimeStamp: timestampForTouch(touch),
|
|
67
58
|
startPageX: touch.pageX,
|
|
68
59
|
startPageY: touch.pageY,
|
|
60
|
+
startTimeStamp: timestampForTouch(touch),
|
|
69
61
|
currentPageX: touch.pageX,
|
|
70
62
|
currentPageY: touch.pageY,
|
|
71
63
|
currentTimeStamp: timestampForTouch(touch),
|
|
@@ -73,91 +65,101 @@ var initializeTouchData = function (touch) {
|
|
|
73
65
|
previousPageY: touch.pageY,
|
|
74
66
|
previousTimeStamp: timestampForTouch(touch)
|
|
75
67
|
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
var identifier =
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
var
|
|
101
|
-
var
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
validateTouch(touch);
|
|
105
|
-
}
|
|
106
|
-
if (touchTrack) {
|
|
107
|
-
reinitializeTouchTrack(touchTrack, touch);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function resetTouchRecord(touchRecord, touch) {
|
|
71
|
+
touchRecord.touchActive = true;
|
|
72
|
+
touchRecord.startPageX = touch.pageX;
|
|
73
|
+
touchRecord.startPageY = touch.pageY;
|
|
74
|
+
touchRecord.startTimeStamp = timestampForTouch(touch);
|
|
75
|
+
touchRecord.currentPageX = touch.pageX;
|
|
76
|
+
touchRecord.currentPageY = touch.pageY;
|
|
77
|
+
touchRecord.currentTimeStamp = timestampForTouch(touch);
|
|
78
|
+
touchRecord.previousPageX = touch.pageX;
|
|
79
|
+
touchRecord.previousPageY = touch.pageY;
|
|
80
|
+
touchRecord.previousTimeStamp = timestampForTouch(touch);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function getTouchIdentifier(_ref) {
|
|
84
|
+
var identifier = _ref.identifier;
|
|
85
|
+
|
|
86
|
+
!(identifier != null) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Touch object is missing identifier.') : _prodInvariant('138') : void 0;
|
|
87
|
+
process.env.NODE_ENV !== 'production' ? warning(identifier <= MAX_TOUCH_BANK, 'Touch identifier %s is greater than maximum supported %s which causes ' + 'performance issues backfilling array locations for all of the indices.', identifier, MAX_TOUCH_BANK) : void 0;
|
|
88
|
+
return identifier;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function recordTouchStart(touch) {
|
|
92
|
+
var identifier = getTouchIdentifier(touch);
|
|
93
|
+
var touchRecord = touchBank[identifier];
|
|
94
|
+
if (touchRecord) {
|
|
95
|
+
resetTouchRecord(touchRecord, touch);
|
|
108
96
|
} else {
|
|
109
|
-
touchBank[
|
|
97
|
+
touchBank[identifier] = createTouchRecord(touch);
|
|
110
98
|
}
|
|
111
99
|
touchHistory.mostRecentTimeStamp = timestampForTouch(touch);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
var
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function recordTouchMove(touch) {
|
|
103
|
+
var touchRecord = touchBank[getTouchIdentifier(touch)];
|
|
104
|
+
if (touchRecord) {
|
|
105
|
+
touchRecord.touchActive = true;
|
|
106
|
+
touchRecord.previousPageX = touchRecord.currentPageX;
|
|
107
|
+
touchRecord.previousPageY = touchRecord.currentPageY;
|
|
108
|
+
touchRecord.previousTimeStamp = touchRecord.currentTimeStamp;
|
|
109
|
+
touchRecord.currentPageX = touch.pageX;
|
|
110
|
+
touchRecord.currentPageY = touch.pageY;
|
|
111
|
+
touchRecord.currentTimeStamp = timestampForTouch(touch);
|
|
112
|
+
touchHistory.mostRecentTimeStamp = timestampForTouch(touch);
|
|
113
|
+
} else {
|
|
114
|
+
console.error('Cannot record touch move without a touch start.\n' + 'Touch Move: %s\n', 'Touch Bank: %s', printTouch(touch), printTouchBank());
|
|
120
115
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
!touchTrack ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Touch data should have been recorded on start') : _prodInvariant('134') : void 0;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function recordTouchEnd(touch) {
|
|
119
|
+
var touchRecord = touchBank[getTouchIdentifier(touch)];
|
|
120
|
+
if (touchRecord) {
|
|
121
|
+
touchRecord.touchActive = false;
|
|
122
|
+
touchRecord.previousPageX = touchRecord.currentPageX;
|
|
123
|
+
touchRecord.previousPageY = touchRecord.currentPageY;
|
|
124
|
+
touchRecord.previousTimeStamp = touchRecord.currentTimeStamp;
|
|
125
|
+
touchRecord.currentPageX = touch.pageX;
|
|
126
|
+
touchRecord.currentPageY = touch.pageY;
|
|
127
|
+
touchRecord.currentTimeStamp = timestampForTouch(touch);
|
|
128
|
+
touchHistory.mostRecentTimeStamp = timestampForTouch(touch);
|
|
129
|
+
} else {
|
|
130
|
+
console.error('Cannot record touch end without a touch start.\n' + 'Touch End: %s\n', 'Touch Bank: %s', printTouch(touch), printTouchBank());
|
|
137
131
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function printTouch(touch) {
|
|
135
|
+
return JSON.stringify({
|
|
136
|
+
identifier: touch.identifier,
|
|
137
|
+
pageX: touch.pageX,
|
|
138
|
+
pageY: touch.pageY,
|
|
139
|
+
timestamp: timestampForTouch(touch)
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function printTouchBank() {
|
|
144
|
+
var printed = JSON.stringify(touchBank.slice(0, MAX_TOUCH_BANK));
|
|
145
|
+
if (touchBank.length > MAX_TOUCH_BANK) {
|
|
146
|
+
printed += ' (original size: ' + touchBank.length + ')';
|
|
147
|
+
}
|
|
148
|
+
return printed;
|
|
149
|
+
}
|
|
147
150
|
|
|
148
151
|
var ResponderTouchHistoryStore = {
|
|
149
152
|
recordTouchTrack: function (topLevelType, nativeEvent) {
|
|
150
|
-
var touchBank = touchHistory.touchBank;
|
|
151
153
|
if (isMoveish(topLevelType)) {
|
|
152
|
-
nativeEvent.changedTouches.forEach(
|
|
154
|
+
nativeEvent.changedTouches.forEach(recordTouchMove);
|
|
153
155
|
} else if (isStartish(topLevelType)) {
|
|
154
|
-
nativeEvent.changedTouches.forEach(
|
|
156
|
+
nativeEvent.changedTouches.forEach(recordTouchStart);
|
|
155
157
|
touchHistory.numberActiveTouches = nativeEvent.touches.length;
|
|
156
158
|
if (touchHistory.numberActiveTouches === 1) {
|
|
157
159
|
touchHistory.indexOfSingleActiveTouch = nativeEvent.touches[0].identifier;
|
|
158
160
|
}
|
|
159
161
|
} else if (isEndish(topLevelType)) {
|
|
160
|
-
nativeEvent.changedTouches.forEach(
|
|
162
|
+
nativeEvent.changedTouches.forEach(recordTouchEnd);
|
|
161
163
|
touchHistory.numberActiveTouches = nativeEvent.touches.length;
|
|
162
164
|
if (touchHistory.numberActiveTouches === 1) {
|
|
163
165
|
for (var i = 0; i < touchBank.length; i++) {
|
|
@@ -168,14 +170,14 @@ var ResponderTouchHistoryStore = {
|
|
|
168
170
|
}
|
|
169
171
|
}
|
|
170
172
|
if (process.env.NODE_ENV !== 'production') {
|
|
171
|
-
var
|
|
172
|
-
|
|
173
|
-
!foundActive ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Cannot find single active touch') : _prodInvariant('135') : void 0;
|
|
173
|
+
var activeRecord = touchBank[touchHistory.indexOfSingleActiveTouch];
|
|
174
|
+
process.env.NODE_ENV !== 'production' ? warning(activeRecord != null && activeRecord.touchActive, 'Cannot find single active touch.') : void 0;
|
|
174
175
|
}
|
|
175
176
|
}
|
|
176
177
|
}
|
|
177
178
|
},
|
|
178
179
|
|
|
180
|
+
|
|
179
181
|
touchHistory: touchHistory
|
|
180
182
|
};
|
|
181
183
|
|