react 0.6.2 → 0.8.0
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/README.md +15 -217
- package/ReactJSErrors.js +40 -0
- package/addons.js +4 -0
- package/lib/$.js +46 -0
- package/lib/CSSCore.js +114 -0
- package/lib/CSSProperty.js +90 -0
- package/lib/CSSPropertyOperations.js +97 -0
- package/lib/CallbackRegistry.js +91 -0
- package/lib/ChangeEventPlugin.js +365 -0
- package/lib/CompositionEventPlugin.js +212 -0
- package/lib/DOMChildrenOperations.js +135 -0
- package/lib/DOMProperty.js +266 -0
- package/lib/DOMPropertyOperations.js +168 -0
- package/lib/Danger.js +186 -0
- package/lib/DefaultDOMPropertyConfig.js +187 -0
- package/lib/DefaultEventPluginOrder.js +44 -0
- package/lib/EnterLeaveEventPlugin.js +112 -0
- package/lib/EventConstants.js +73 -0
- package/lib/EventListener.js +61 -0
- package/lib/EventPluginHub.js +190 -0
- package/lib/EventPluginRegistry.js +237 -0
- package/lib/EventPluginUtils.js +185 -0
- package/lib/EventPropagators.js +179 -0
- package/lib/ExecutionEnvironment.js +41 -0
- package/lib/LinkedStateMixin.js +46 -0
- package/lib/LinkedValueMixin.js +68 -0
- package/lib/MobileSafariClickEventPlugin.js +63 -0
- package/lib/PooledClass.js +113 -0
- package/lib/React.js +71 -0
- package/lib/ReactChildren.js +132 -0
- package/lib/ReactComponent.js +515 -0
- package/lib/ReactComponentBrowserEnvironment.js +140 -0
- package/lib/ReactComponentEnvironment.js +24 -0
- package/lib/ReactCompositeComponent.js +1020 -0
- package/lib/ReactCurrentOwner.js +39 -0
- package/lib/ReactDOM.js +194 -0
- package/lib/ReactDOMButton.js +64 -0
- package/lib/ReactDOMComponent.js +374 -0
- package/lib/ReactDOMForm.js +52 -0
- package/lib/ReactDOMIDOperations.js +173 -0
- package/lib/ReactDOMInput.js +169 -0
- package/lib/ReactDOMOption.js +50 -0
- package/lib/ReactDOMSelect.js +160 -0
- package/lib/ReactDOMSelection.js +189 -0
- package/lib/ReactDOMTextarea.js +136 -0
- package/lib/ReactDefaultBatchingStrategy.js +75 -0
- package/lib/ReactDefaultInjection.js +91 -0
- package/lib/ReactDefaultPerf.js +407 -0
- package/lib/ReactErrorUtils.js +46 -0
- package/lib/ReactEventEmitter.js +341 -0
- package/lib/ReactEventEmitterMixin.js +89 -0
- package/lib/ReactEventTopLevelCallback.js +89 -0
- package/lib/ReactInputSelection.js +140 -0
- package/lib/ReactInstanceHandles.js +322 -0
- package/lib/ReactLink.js +54 -0
- package/lib/ReactMarkupChecksum.js +53 -0
- package/lib/ReactMount.js +617 -0
- package/lib/ReactMountReady.js +95 -0
- package/lib/ReactMultiChild.js +441 -0
- package/lib/ReactMultiChildUpdateTypes.js +36 -0
- package/lib/ReactOwner.js +146 -0
- package/lib/ReactPerf.js +88 -0
- package/lib/ReactPropTransferer.js +128 -0
- package/lib/ReactPropTypes.js +158 -0
- package/lib/ReactReconcileTransaction.js +161 -0
- package/lib/ReactServerRendering.js +62 -0
- package/lib/ReactStateSetters.js +111 -0
- package/lib/ReactTextComponent.js +94 -0
- package/lib/ReactTransitionEvents.js +97 -0
- package/lib/ReactTransitionGroup.js +112 -0
- package/lib/ReactTransitionKeySet.js +111 -0
- package/lib/ReactTransitionableChild.js +152 -0
- package/lib/ReactUpdates.js +145 -0
- package/lib/ReactWithAddons.js +41 -0
- package/lib/SelectEventPlugin.js +217 -0
- package/lib/SimpleEventPlugin.js +365 -0
- package/lib/SyntheticClipboardEvent.js +45 -0
- package/lib/SyntheticCompositionEvent.js +51 -0
- package/lib/SyntheticEvent.js +163 -0
- package/lib/SyntheticFocusEvent.js +44 -0
- package/lib/SyntheticKeyboardEvent.js +56 -0
- package/lib/SyntheticMouseEvent.js +85 -0
- package/lib/SyntheticTouchEvent.js +50 -0
- package/lib/SyntheticUIEvent.js +45 -0
- package/lib/SyntheticWheelEvent.js +63 -0
- package/lib/Transaction.js +251 -0
- package/lib/ViewportMetrics.js +37 -0
- package/lib/accumulate.js +54 -0
- package/lib/adler32.js +39 -0
- package/lib/containsNode.js +49 -0
- package/lib/copyProperties.js +54 -0
- package/lib/createArrayFrom.js +94 -0
- package/lib/createNodesFromMarkup.js +93 -0
- package/lib/createObjectFrom.js +61 -0
- package/lib/cx.js +44 -0
- package/lib/dangerousStyleValue.js +57 -0
- package/lib/emptyFunction.js +43 -0
- package/lib/escapeTextForBrowser.js +47 -0
- package/lib/ex.js +49 -0
- package/lib/filterAttributes.js +45 -0
- package/lib/flattenChildren.js +54 -0
- package/lib/forEachAccumulated.js +36 -0
- package/lib/ge.js +76 -0
- package/lib/getActiveElement.js +33 -0
- package/lib/getEventTarget.js +36 -0
- package/lib/getMarkupWrap.js +108 -0
- package/lib/getNodeForCharacterOffset.js +80 -0
- package/lib/getReactRootElementInContainer.js +40 -0
- package/lib/getTextContentAccessor.js +40 -0
- package/lib/getUnboundedScrollPosition.js +45 -0
- package/lib/hyphenate.js +35 -0
- package/lib/invariant.js +54 -0
- package/lib/isEventSupported.js +74 -0
- package/lib/isNode.js +33 -0
- package/lib/isTextInputElement.js +49 -0
- package/lib/isTextNode.js +30 -0
- package/lib/joinClasses.js +44 -0
- package/lib/keyMirror.js +58 -0
- package/lib/keyOf.js +41 -0
- package/lib/memoizeStringOnly.js +39 -0
- package/lib/merge.js +37 -0
- package/lib/mergeHelpers.js +137 -0
- package/lib/mergeInto.js +45 -0
- package/lib/mixInto.js +34 -0
- package/lib/mutateHTMLNodeWithMarkup.js +100 -0
- package/lib/objMap.js +47 -0
- package/lib/objMapKeyVal.js +47 -0
- package/lib/performanceNow.js +42 -0
- package/lib/shallowEqual.js +49 -0
- package/lib/traverseAllChildren.js +127 -0
- package/package.json +33 -21
- package/react.js +4 -0
- package/.npmignore +0 -7
- package/.travis.yml +0 -5
- package/Jakefile.js +0 -39
- package/LICENSE +0 -19
- package/browser-test/dist.html +0 -89
- package/browser-test/index.html +0 -85
- package/browser-test/min.html +0 -89
- package/dist/react.js +0 -3094
- package/dist/react.min.js +0 -22
- package/doc/advanced.md +0 -166
- package/doc/color-def.graffle +0 -938
- package/doc/color-def.png +0 -0
- package/doc/simple.dot +0 -25
- package/doc/simple.png +0 -0
- package/examples/longer-example.js +0 -41
- package/examples/simple.js +0 -45
- package/examples/using-ast-directly.js +0 -30
- package/examples/using-events1.js +0 -79
- package/examples/using-log-events.js +0 -43
- package/lib/base-task.js +0 -123
- package/lib/cb-task.js +0 -84
- package/lib/core.js +0 -138
- package/lib/dsl.js +0 -138
- package/lib/error.js +0 -55
- package/lib/event-collector.js +0 -81
- package/lib/event-manager.js +0 -85
- package/lib/eventemitter.js +0 -20
- package/lib/finalcb-first-task.js +0 -68
- package/lib/finalcb-task.js +0 -65
- package/lib/id.js +0 -22
- package/lib/input-parser.js +0 -56
- package/lib/log-events.js +0 -92
- package/lib/parse.js +0 -41
- package/lib/promise-resolve.js +0 -50
- package/lib/promise-task.js +0 -93
- package/lib/react.js +0 -59
- package/lib/ret-task.js +0 -71
- package/lib/sprintf.js +0 -18
- package/lib/status.js +0 -14
- package/lib/task.js +0 -251
- package/lib/track-tasks.js +0 -74
- package/lib/validate.js +0 -159
- package/lib/vcon.js +0 -90
- package/lib/when-task.js +0 -85
- package/src/dist.build.requirejs +0 -20
- package/test/ast.mocha.js +0 -136
- package/test/cb-task.mocha.js +0 -220
- package/test/core-deferred.mocha.js +0 -143
- package/test/core-when.mocha.js +0 -96
- package/test/core.mocha.js +0 -589
- package/test/dsl.mocha.js +0 -350
- package/test/event-manager.mocha.js +0 -119
- package/test/exec-options.mocha.js +0 -48
- package/test/finalcb-task.mocha.js +0 -58
- package/test/input-parser.mocha.js +0 -86
- package/test/mocha.opts +0 -2
- package/test/module-use.mocha.js +0 -147
- package/test/promise-auto-resolve.mocha.js +0 -68
- package/test/ret-task.mocha.js +0 -220
- package/test/task.mocha.js +0 -42
- package/test/validate-cb-task.mocha.js +0 -100
- package/test/validate-ret-task.mocha.js +0 -110
- package/test/validate.mocha.js +0 -324
- package/test/vcon.mocha.js +0 -193
- package/vendor/chai/chai.js +0 -2038
- package/vendor/jquery/jquery-1.7.1.js +0 -9266
- package/vendor/jquery/jquery-1.7.1.min.js +0 -4
- package/vendor/mocha/mocha.css +0 -135
- package/vendor/mocha/mocha.js +0 -3589
- package/vendor/node/util.js +0 -531
- package/vendor/requirejs/require.js +0 -2053
- package/vendor/requirejs/require.min.js +0 -33
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013 Facebook, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
* @providesModule SyntheticTouchEvent
|
|
17
|
+
* @typechecks static-only
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
"use strict";
|
|
21
|
+
|
|
22
|
+
var SyntheticUIEvent = require("./SyntheticUIEvent");
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @interface TouchEvent
|
|
26
|
+
* @see http://www.w3.org/TR/touch-events/
|
|
27
|
+
*/
|
|
28
|
+
var TouchEventInterface = {
|
|
29
|
+
touches: null,
|
|
30
|
+
targetTouches: null,
|
|
31
|
+
changedTouches: null,
|
|
32
|
+
altKey: null,
|
|
33
|
+
metaKey: null,
|
|
34
|
+
ctrlKey: null,
|
|
35
|
+
shiftKey: null
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @param {object} dispatchConfig Configuration used to dispatch this event.
|
|
40
|
+
* @param {string} dispatchMarker Marker identifying the event target.
|
|
41
|
+
* @param {object} nativeEvent Native browser event.
|
|
42
|
+
* @extends {SyntheticUIEvent}
|
|
43
|
+
*/
|
|
44
|
+
function SyntheticTouchEvent(dispatchConfig, dispatchMarker, nativeEvent) {
|
|
45
|
+
SyntheticUIEvent.call(this, dispatchConfig, dispatchMarker, nativeEvent);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
SyntheticUIEvent.augmentClass(SyntheticTouchEvent, TouchEventInterface);
|
|
49
|
+
|
|
50
|
+
module.exports = SyntheticTouchEvent;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013 Facebook, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
* @providesModule SyntheticUIEvent
|
|
17
|
+
* @typechecks static-only
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
"use strict";
|
|
21
|
+
|
|
22
|
+
var SyntheticEvent = require("./SyntheticEvent");
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @interface UIEvent
|
|
26
|
+
* @see http://www.w3.org/TR/DOM-Level-3-Events/
|
|
27
|
+
*/
|
|
28
|
+
var UIEventInterface = {
|
|
29
|
+
view: null,
|
|
30
|
+
detail: null
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @param {object} dispatchConfig Configuration used to dispatch this event.
|
|
35
|
+
* @param {string} dispatchMarker Marker identifying the event target.
|
|
36
|
+
* @param {object} nativeEvent Native browser event.
|
|
37
|
+
* @extends {SyntheticEvent}
|
|
38
|
+
*/
|
|
39
|
+
function SyntheticUIEvent(dispatchConfig, dispatchMarker, nativeEvent) {
|
|
40
|
+
SyntheticEvent.call(this, dispatchConfig, dispatchMarker, nativeEvent);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
SyntheticEvent.augmentClass(SyntheticUIEvent, UIEventInterface);
|
|
44
|
+
|
|
45
|
+
module.exports = SyntheticUIEvent;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013 Facebook, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
* @providesModule SyntheticWheelEvent
|
|
17
|
+
* @typechecks static-only
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
"use strict";
|
|
21
|
+
|
|
22
|
+
var SyntheticMouseEvent = require("./SyntheticMouseEvent");
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @interface WheelEvent
|
|
26
|
+
* @see http://www.w3.org/TR/DOM-Level-3-Events/
|
|
27
|
+
*/
|
|
28
|
+
var WheelEventInterface = {
|
|
29
|
+
deltaX: function(event) {
|
|
30
|
+
// NOTE: IE<9 does not support x-axis delta.
|
|
31
|
+
return (
|
|
32
|
+
'deltaX' in event ? event.deltaX :
|
|
33
|
+
// Fallback to `wheelDeltaX` for Webkit and normalize (right is positive).
|
|
34
|
+
'wheelDeltaX' in event ? -event.wheelDeltaX : 0
|
|
35
|
+
);
|
|
36
|
+
},
|
|
37
|
+
deltaY: function(event) {
|
|
38
|
+
return (
|
|
39
|
+
// Normalize (up is positive).
|
|
40
|
+
'deltaY' in event ? -event.deltaY :
|
|
41
|
+
// Fallback to `wheelDeltaY` for Webkit.
|
|
42
|
+
'wheelDeltaY' in event ? event.wheelDeltaY :
|
|
43
|
+
// Fallback to `wheelDelta` for IE<9.
|
|
44
|
+
'wheelDelta' in event ? event.wheelDelta : 0
|
|
45
|
+
);
|
|
46
|
+
},
|
|
47
|
+
deltaZ: null,
|
|
48
|
+
deltaMode: null
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param {object} dispatchConfig Configuration used to dispatch this event.
|
|
53
|
+
* @param {string} dispatchMarker Marker identifying the event target.
|
|
54
|
+
* @param {object} nativeEvent Native browser event.
|
|
55
|
+
* @extends {SyntheticMouseEvent}
|
|
56
|
+
*/
|
|
57
|
+
function SyntheticWheelEvent(dispatchConfig, dispatchMarker, nativeEvent) {
|
|
58
|
+
SyntheticMouseEvent.call(this, dispatchConfig, dispatchMarker, nativeEvent);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
SyntheticMouseEvent.augmentClass(SyntheticWheelEvent, WheelEventInterface);
|
|
62
|
+
|
|
63
|
+
module.exports = SyntheticWheelEvent;
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013 Facebook, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
* @providesModule Transaction
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
"use strict";
|
|
20
|
+
|
|
21
|
+
var invariant = require("./invariant");
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* `Transaction` creates a black box that is able to wrap any method such that
|
|
25
|
+
* certain invariants are maintained before and after the method is invoked
|
|
26
|
+
* (Even if an exception is thrown while invoking the wrapped method). Whoever
|
|
27
|
+
* instantiates a transaction can provide enforcers of the invariants at
|
|
28
|
+
* creation time. The `Transaction` class itself will supply one additional
|
|
29
|
+
* automatic invariant for you - the invariant that any transaction instance
|
|
30
|
+
* should not be ran while it is already being ran. You would typically create a
|
|
31
|
+
* single instance of a `Transaction` for reuse multiple times, that potentially
|
|
32
|
+
* is used to wrap several different methods. Wrappers are extremely simple -
|
|
33
|
+
* they only require implementing two methods.
|
|
34
|
+
*
|
|
35
|
+
* <pre>
|
|
36
|
+
* wrappers (injected at creation time)
|
|
37
|
+
* + +
|
|
38
|
+
* | |
|
|
39
|
+
* +-----------------|--------|--------------+
|
|
40
|
+
* | v | |
|
|
41
|
+
* | +---------------+ | |
|
|
42
|
+
* | +--| wrapper1 |---|----+ |
|
|
43
|
+
* | | +---------------+ v | |
|
|
44
|
+
* | | +-------------+ | |
|
|
45
|
+
* | | +----| wrapper2 |--------+ |
|
|
46
|
+
* | | | +-------------+ | | |
|
|
47
|
+
* | | | | | |
|
|
48
|
+
* | v v v v | wrapper
|
|
49
|
+
* | +---+ +---+ +---------+ +---+ +---+ | invariants
|
|
50
|
+
* perform(anyMethod) | | | | | | | | | | | | maintained
|
|
51
|
+
* +----------------->|-|---|-|---|-->|anyMethod|---|---|-|---|-|-------->
|
|
52
|
+
* | | | | | | | | | | | |
|
|
53
|
+
* | | | | | | | | | | | |
|
|
54
|
+
* | | | | | | | | | | | |
|
|
55
|
+
* | +---+ +---+ +---------+ +---+ +---+ |
|
|
56
|
+
* | initialize close |
|
|
57
|
+
* +-----------------------------------------+
|
|
58
|
+
* </pre>
|
|
59
|
+
*
|
|
60
|
+
* Bonus:
|
|
61
|
+
* - Reports timing metrics by method name and wrapper index.
|
|
62
|
+
*
|
|
63
|
+
* Use cases:
|
|
64
|
+
* - Preserving the input selection ranges before/after reconciliation.
|
|
65
|
+
* Restoring selection even in the event of an unexpected error.
|
|
66
|
+
* - Deactivating events while rearranging the DOM, preventing blurs/focuses,
|
|
67
|
+
* while guaranteeing that afterwards, the event system is reactivated.
|
|
68
|
+
* - Flushing a queue of collected DOM mutations to the main UI thread after a
|
|
69
|
+
* reconciliation takes place in a worker thread.
|
|
70
|
+
* - Invoking any collected `componentDidRender` callbacks after rendering new
|
|
71
|
+
* content.
|
|
72
|
+
* - (Future use case): Wrapping particular flushes of the `ReactWorker` queue
|
|
73
|
+
* to preserve the `scrollTop` (an automatic scroll aware DOM).
|
|
74
|
+
* - (Future use case): Layout calculations before and after DOM upates.
|
|
75
|
+
*
|
|
76
|
+
* Transactional plugin API:
|
|
77
|
+
* - A module that has an `initialize` method that returns any precomputation.
|
|
78
|
+
* - and a `close` method that accepts the precomputation. `close` is invoked
|
|
79
|
+
* when the wrapped process is completed, or has failed.
|
|
80
|
+
*
|
|
81
|
+
* @param {Array<TransactionalWrapper>} transactionWrapper Wrapper modules
|
|
82
|
+
* that implement `initialize` and `close`.
|
|
83
|
+
* @return {Transaction} Single transaction for reuse in thread.
|
|
84
|
+
*
|
|
85
|
+
* @class Transaction
|
|
86
|
+
*/
|
|
87
|
+
var Mixin = {
|
|
88
|
+
/**
|
|
89
|
+
* Sets up this instance so that it is prepared for collecting metrics. Does
|
|
90
|
+
* so such that this setup method may be used on an instance that is already
|
|
91
|
+
* initialized, in a way that does not consume additional memory upon reuse.
|
|
92
|
+
* That can be useful if you decide to make your subclass of this mixin a
|
|
93
|
+
* "PooledClass".
|
|
94
|
+
*/
|
|
95
|
+
reinitializeTransaction: function() {
|
|
96
|
+
this.transactionWrappers = this.getTransactionWrappers();
|
|
97
|
+
if (!this.wrapperInitData) {
|
|
98
|
+
this.wrapperInitData = [];
|
|
99
|
+
} else {
|
|
100
|
+
this.wrapperInitData.length = 0;
|
|
101
|
+
}
|
|
102
|
+
if (!this.timingMetrics) {
|
|
103
|
+
this.timingMetrics = {};
|
|
104
|
+
}
|
|
105
|
+
this.timingMetrics.methodInvocationTime = 0;
|
|
106
|
+
if (!this.timingMetrics.wrapperInitTimes) {
|
|
107
|
+
this.timingMetrics.wrapperInitTimes = [];
|
|
108
|
+
} else {
|
|
109
|
+
this.timingMetrics.wrapperInitTimes.length = 0;
|
|
110
|
+
}
|
|
111
|
+
if (!this.timingMetrics.wrapperCloseTimes) {
|
|
112
|
+
this.timingMetrics.wrapperCloseTimes = [];
|
|
113
|
+
} else {
|
|
114
|
+
this.timingMetrics.wrapperCloseTimes.length = 0;
|
|
115
|
+
}
|
|
116
|
+
this._isInTransaction = false;
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
_isInTransaction: false,
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @abstract
|
|
123
|
+
* @return {Array<TransactionWrapper>} Array of transaction wrappers.
|
|
124
|
+
*/
|
|
125
|
+
getTransactionWrappers: null,
|
|
126
|
+
|
|
127
|
+
isInTransaction: function() {
|
|
128
|
+
return !!this._isInTransaction;
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Executes the function within a safety window. Use this for the top level
|
|
133
|
+
* methods that result in large amounts of computation/mutations that would
|
|
134
|
+
* need to be safety checked.
|
|
135
|
+
*
|
|
136
|
+
* @param {function} method Member of scope to call.
|
|
137
|
+
* @param {Object} scope Scope to invoke from.
|
|
138
|
+
* @param {Object?=} args... Arguments to pass to the method (optional).
|
|
139
|
+
* Helps prevent need to bind in many cases.
|
|
140
|
+
* @return Return value from `method`.
|
|
141
|
+
*/
|
|
142
|
+
perform: function(method, scope, a, b, c, d, e, f) {
|
|
143
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
144
|
+
!this.isInTransaction(),
|
|
145
|
+
'Transaction.perform(...): Cannot initialize a transaction when there ' +
|
|
146
|
+
'is already an outstanding transaction.'
|
|
147
|
+
) : invariant(!this.isInTransaction()));
|
|
148
|
+
var memberStart = Date.now();
|
|
149
|
+
var errorToThrow = null;
|
|
150
|
+
var ret;
|
|
151
|
+
try {
|
|
152
|
+
this.initializeAll();
|
|
153
|
+
ret = method.call(scope, a, b, c, d, e, f);
|
|
154
|
+
} catch (error) {
|
|
155
|
+
// IE8 requires `catch` in order to use `finally`.
|
|
156
|
+
errorToThrow = error;
|
|
157
|
+
} finally {
|
|
158
|
+
var memberEnd = Date.now();
|
|
159
|
+
this.methodInvocationTime += (memberEnd - memberStart);
|
|
160
|
+
try {
|
|
161
|
+
this.closeAll();
|
|
162
|
+
} catch (closeError) {
|
|
163
|
+
// If `method` throws, prefer to show that stack trace over any thrown
|
|
164
|
+
// by invoking `closeAll`.
|
|
165
|
+
errorToThrow = errorToThrow || closeError;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (errorToThrow) {
|
|
169
|
+
throw errorToThrow;
|
|
170
|
+
}
|
|
171
|
+
return ret;
|
|
172
|
+
},
|
|
173
|
+
|
|
174
|
+
initializeAll: function() {
|
|
175
|
+
this._isInTransaction = true;
|
|
176
|
+
var transactionWrappers = this.transactionWrappers;
|
|
177
|
+
var wrapperInitTimes = this.timingMetrics.wrapperInitTimes;
|
|
178
|
+
var errorToThrow = null;
|
|
179
|
+
for (var i = 0; i < transactionWrappers.length; i++) {
|
|
180
|
+
var initStart = Date.now();
|
|
181
|
+
var wrapper = transactionWrappers[i];
|
|
182
|
+
try {
|
|
183
|
+
this.wrapperInitData[i] = wrapper.initialize ?
|
|
184
|
+
wrapper.initialize.call(this) :
|
|
185
|
+
null;
|
|
186
|
+
} catch (initError) {
|
|
187
|
+
// Prefer to show the stack trace of the first error.
|
|
188
|
+
errorToThrow = errorToThrow || initError;
|
|
189
|
+
this.wrapperInitData[i] = Transaction.OBSERVED_ERROR;
|
|
190
|
+
} finally {
|
|
191
|
+
var curInitTime = wrapperInitTimes[i];
|
|
192
|
+
var initEnd = Date.now();
|
|
193
|
+
wrapperInitTimes[i] = (curInitTime || 0) + (initEnd - initStart);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (errorToThrow) {
|
|
197
|
+
throw errorToThrow;
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Invokes each of `this.transactionWrappers.close[i]` functions, passing into
|
|
203
|
+
* them the respective return values of `this.transactionWrappers.init[i]`
|
|
204
|
+
* (`close`rs that correspond to initializers that failed will not be
|
|
205
|
+
* invoked).
|
|
206
|
+
*/
|
|
207
|
+
closeAll: function() {
|
|
208
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
209
|
+
this.isInTransaction(),
|
|
210
|
+
'Transaction.closeAll(): Cannot close transaction when none are open.'
|
|
211
|
+
) : invariant(this.isInTransaction()));
|
|
212
|
+
var transactionWrappers = this.transactionWrappers;
|
|
213
|
+
var wrapperCloseTimes = this.timingMetrics.wrapperCloseTimes;
|
|
214
|
+
var errorToThrow = null;
|
|
215
|
+
for (var i = 0; i < transactionWrappers.length; i++) {
|
|
216
|
+
var wrapper = transactionWrappers[i];
|
|
217
|
+
var closeStart = Date.now();
|
|
218
|
+
var initData = this.wrapperInitData[i];
|
|
219
|
+
try {
|
|
220
|
+
if (initData !== Transaction.OBSERVED_ERROR) {
|
|
221
|
+
wrapper.close && wrapper.close.call(this, initData);
|
|
222
|
+
}
|
|
223
|
+
} catch (closeError) {
|
|
224
|
+
// Prefer to show the stack trace of the first error.
|
|
225
|
+
errorToThrow = errorToThrow || closeError;
|
|
226
|
+
} finally {
|
|
227
|
+
var closeEnd = Date.now();
|
|
228
|
+
var curCloseTime = wrapperCloseTimes[i];
|
|
229
|
+
wrapperCloseTimes[i] = (curCloseTime || 0) + (closeEnd - closeStart);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
this.wrapperInitData.length = 0;
|
|
233
|
+
this._isInTransaction = false;
|
|
234
|
+
if (errorToThrow) {
|
|
235
|
+
throw errorToThrow;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
var Transaction = {
|
|
241
|
+
|
|
242
|
+
Mixin: Mixin,
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Token to look for to determine if an error occured.
|
|
246
|
+
*/
|
|
247
|
+
OBSERVED_ERROR: {}
|
|
248
|
+
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
module.exports = Transaction;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013 Facebook, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
* @providesModule ViewportMetrics
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
"use strict";
|
|
20
|
+
|
|
21
|
+
var getUnboundedScrollPosition = require("./getUnboundedScrollPosition");
|
|
22
|
+
|
|
23
|
+
var ViewportMetrics = {
|
|
24
|
+
|
|
25
|
+
currentScrollLeft: 0,
|
|
26
|
+
|
|
27
|
+
currentScrollTop: 0,
|
|
28
|
+
|
|
29
|
+
refreshScrollValues: function() {
|
|
30
|
+
var scrollPosition = getUnboundedScrollPosition(window);
|
|
31
|
+
ViewportMetrics.currentScrollLeft = scrollPosition.x;
|
|
32
|
+
ViewportMetrics.currentScrollTop = scrollPosition.y;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
module.exports = ViewportMetrics;
|