2015-01-30 01:10:49 +00:00
|
|
|
/**
|
2015-03-23 22:07:33 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
2015-01-30 01:10:49 +00:00
|
|
|
*
|
|
|
|
* @providesModule ReactIOS
|
2015-03-26 01:19:28 +00:00
|
|
|
* @flow
|
2015-01-30 01:10:49 +00:00
|
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
|
2015-03-02 18:45:03 +00:00
|
|
|
var ReactChildren = require('ReactChildren');
|
2015-03-09 05:39:23 +00:00
|
|
|
var ReactClass = require('ReactClass');
|
2015-01-30 01:10:49 +00:00
|
|
|
var ReactComponent = require('ReactComponent');
|
|
|
|
var ReactContext = require('ReactContext');
|
|
|
|
var ReactCurrentOwner = require('ReactCurrentOwner');
|
|
|
|
var ReactElement = require('ReactElement');
|
|
|
|
var ReactElementValidator = require('ReactElementValidator');
|
|
|
|
var ReactInstanceHandles = require('ReactInstanceHandles');
|
|
|
|
var ReactIOSDefaultInjection = require('ReactIOSDefaultInjection');
|
|
|
|
var ReactIOSMount = require('ReactIOSMount');
|
|
|
|
var ReactPropTypes = require('ReactPropTypes');
|
|
|
|
|
|
|
|
var deprecated = require('deprecated');
|
|
|
|
var invariant = require('invariant');
|
2015-03-02 18:45:03 +00:00
|
|
|
var onlyChild = require('onlyChild');
|
2015-01-30 01:10:49 +00:00
|
|
|
|
|
|
|
ReactIOSDefaultInjection.inject();
|
|
|
|
|
|
|
|
var createElement = ReactElement.createElement;
|
|
|
|
var createFactory = ReactElement.createFactory;
|
2015-03-09 05:39:23 +00:00
|
|
|
var cloneElement = ReactElement.cloneElement;
|
2015-01-30 01:10:49 +00:00
|
|
|
|
|
|
|
if (__DEV__) {
|
|
|
|
createElement = ReactElementValidator.createElement;
|
|
|
|
createFactory = ReactElementValidator.createFactory;
|
2015-03-09 05:39:23 +00:00
|
|
|
cloneElement = ReactElementValidator.cloneElement;
|
2015-01-30 01:10:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var resolveDefaultProps = function(element) {
|
|
|
|
// Could be optimized, but not currently in heavy use.
|
|
|
|
var defaultProps = element.type.defaultProps;
|
|
|
|
var props = element.props;
|
|
|
|
for (var propName in defaultProps) {
|
|
|
|
if (props[propName] === undefined) {
|
|
|
|
props[propName] = defaultProps[propName];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Experimental optimized element creation
|
2015-03-26 01:19:28 +00:00
|
|
|
var augmentElement = function(element: ReactElement) {
|
2015-01-30 01:10:49 +00:00
|
|
|
if (__DEV__) {
|
|
|
|
invariant(
|
|
|
|
false,
|
|
|
|
'This optimized path should never be used in DEV mode because ' +
|
|
|
|
'it does not provide validation. Check your JSX transform.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
element._owner = ReactCurrentOwner.current;
|
|
|
|
element._context = ReactContext.current;
|
|
|
|
if (element.type.defaultProps) {
|
|
|
|
resolveDefaultProps(element);
|
|
|
|
}
|
|
|
|
return element;
|
|
|
|
};
|
|
|
|
|
2015-04-01 02:01:48 +00:00
|
|
|
var render = function(
|
|
|
|
element: ReactElement,
|
|
|
|
mountInto: number,
|
|
|
|
callback?: ?(() => void)
|
|
|
|
): ?ReactComponent {
|
|
|
|
return ReactIOSMount.renderComponent(element, mountInto, callback);
|
2015-01-30 01:10:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var ReactIOS = {
|
|
|
|
hasReactIOSInitialized: false,
|
2015-03-02 18:45:03 +00:00
|
|
|
Children: {
|
|
|
|
map: ReactChildren.map,
|
|
|
|
forEach: ReactChildren.forEach,
|
|
|
|
count: ReactChildren.count,
|
|
|
|
only: onlyChild
|
|
|
|
},
|
2015-03-11 02:11:28 +00:00
|
|
|
Component: ReactComponent,
|
2015-01-30 01:10:49 +00:00
|
|
|
PropTypes: ReactPropTypes,
|
2015-03-09 05:39:23 +00:00
|
|
|
createClass: ReactClass.createClass,
|
2015-01-30 01:10:49 +00:00
|
|
|
createElement: createElement,
|
|
|
|
createFactory: createFactory,
|
2015-03-09 05:39:23 +00:00
|
|
|
cloneElement: cloneElement,
|
2015-01-30 01:10:49 +00:00
|
|
|
_augmentElement: augmentElement,
|
|
|
|
render: render,
|
|
|
|
unmountComponentAtNode: ReactIOSMount.unmountComponentAtNode,
|
|
|
|
|
|
|
|
// Hook for JSX spread, don't use this for anything else.
|
|
|
|
__spread: Object.assign,
|
|
|
|
|
|
|
|
unmountComponentAtNodeAndRemoveContainer: ReactIOSMount.unmountComponentAtNodeAndRemoveContainer,
|
|
|
|
isValidClass: ReactElement.isValidFactory,
|
|
|
|
isValidElement: ReactElement.isValidElement,
|
|
|
|
|
|
|
|
// Deprecations (remove for 0.13)
|
|
|
|
renderComponent: deprecated(
|
|
|
|
'React',
|
|
|
|
'renderComponent',
|
|
|
|
'render',
|
|
|
|
this,
|
|
|
|
render
|
|
|
|
),
|
|
|
|
isValidComponent: deprecated(
|
|
|
|
'React',
|
|
|
|
'isValidComponent',
|
|
|
|
'isValidElement',
|
|
|
|
this,
|
|
|
|
ReactElement.isValidElement
|
|
|
|
)
|
|
|
|
};
|
|
|
|
|
2015-03-23 22:07:33 +00:00
|
|
|
// Inject the runtime into a devtools global hook regardless of browser.
|
|
|
|
// Allows for debugging when the hook is injected on the page.
|
|
|
|
/* globals __REACT_DEVTOOLS_GLOBAL_HOOK__ */
|
|
|
|
if (
|
|
|
|
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
|
|
|
|
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.inject === 'function') {
|
|
|
|
__REACT_DEVTOOLS_GLOBAL_HOOK__.inject({
|
|
|
|
CurrentOwner: ReactCurrentOwner,
|
|
|
|
InstanceHandles: ReactInstanceHandles,
|
|
|
|
Mount: ReactIOSMount,
|
|
|
|
Reconciler: require('ReactReconciler'),
|
|
|
|
TextComponent: require('ReactIOSTextComponent'),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-01-30 01:10:49 +00:00
|
|
|
module.exports = ReactIOS;
|