Skip to content

Commit

Permalink
refactor: move src/isomorphic to es6 modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Darío Javier Cravero committed Jun 11, 2016
1 parent c7868cc commit b244c25
Show file tree
Hide file tree
Showing 19 changed files with 2,682 additions and 124 deletions.
1 change: 0 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"transform-es2015-parameters",
["transform-es2015-destructuring", { "loose": true }],
"transform-es2015-block-scoping",
"transform-es2015-modules-commonjs",
"transform-es3-member-expression-literals",
"transform-es3-property-literals",
"./scripts/babel/transform-object-assign-require",
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"babel-core": "^6.0.0",
"babel-eslint": "^5.0.0",
"babel-plugin-check-es2015-constants": "^6.5.0",
"babel-plugin-external-helpers": "^6.8.0",
"babel-plugin-syntax-trailing-function-commas": "^6.5.0",
"babel-plugin-transform-es2015-arrow-functions": "^6.5.2",
"babel-plugin-transform-es2015-block-scoped-functions": "^6.5.0",
Expand Down Expand Up @@ -59,6 +60,8 @@
"loose-envify": "^1.1.0",
"object-assign": "^4.1.0",
"platform": "^1.1.0",
"rollup": "^0.31.1",
"rollup-plugin-babel": "^2.5.1",
"run-sequence": "^1.1.4",
"through2": "^2.0.0",
"tmp": "~0.0.28",
Expand Down
15 changes: 15 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

import babel from 'rollup-plugin-babel';

export default {
format: 'umd',
moduleName: 'React',
plugins: [
babel({
plugins: [
'external-helpers',
],
}),
],
};
2 changes: 1 addition & 1 deletion src/ReactVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@

'use strict';

module.exports = '16.0.0-alpha';
export default '16.0.0-alpha';
182 changes: 130 additions & 52 deletions src/isomorphic/React.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,74 +9,154 @@
* @providesModule React
*/

/**
* Copyright 2013-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.
*
* @providesModule React
*/

/**
* Copyright 2013-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.
*
* @providesModule React
*/

/**
* Copyright 2013-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.
*
* @providesModule React
*/

/**
* Copyright 2013-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.
*
* @providesModule React
*/

/**
* Copyright 2013-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.
*
* @providesModule React
*/

/**
* Copyright 2013-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.
*
* @providesModule React
*/

/**
* Copyright 2013-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.
*
* @providesModule React
*/

'use strict';

var ReactChildren = require('ReactChildren');
var ReactComponent = require('ReactComponent');
var ReactClass = require('ReactClass');
var ReactDOMFactories = require('ReactDOMFactories');
var ReactElement = require('ReactElement');
var ReactPropTypes = require('ReactPropTypes');
var ReactVersion = require('ReactVersion');

var onlyChild = require('onlyChild');
var warning = require('warning');

var createElement = ReactElement.createElement;
var createFactory = ReactElement.createFactory;
var cloneElement = ReactElement.cloneElement;

if (__DEV__) {
var ReactElementValidator = require('ReactElementValidator');
createElement = ReactElementValidator.createElement;
createFactory = ReactElementValidator.createFactory;
cloneElement = ReactElementValidator.cloneElement;
}
import ReactChildren from './children/ReactChildren';
import ReactComponent from './modern/class/ReactComponent';
import ReactClass from './classic/class/ReactClass';
import ReactDOMFactories from './classic/element/ReactDOMFactories';
import ReactElement from './classic/element/ReactElement';
import ReactElementValidator from './classic/element/ReactElementValidator'; // __DEV__
import ReactPropTypes from './classic/types/ReactPropTypes';
import ReactVersion from '../ReactVersion';
import onlyChild from './children/onlyChild';
import warning from 'warning';

export var createElement = __DEV__ ? ReactElementValidator.createElement : ReactElement.createElement;
export var createFactory = __DEV__ ? ReactElementValidator.createFactory : ReactElement.createFactory;
export var cloneElement = __DEV__ ? ReactElementValidator.cloneElement : ReactElement.cloneElement;

var warned = false;
function spreadWithWarning() {
warning(
warned,
'React.__spread is deprecated and should not be used. Use ' +
'Object.assign directly or another helper function with similar ' +
'semantics. You may be seeing this warning due to your compiler. ' +
'See https://fb.me/react-spread-deprecation for more details.'
);
warned = true;
return Object.assign.apply(null, arguments);
};

var __spread = Object.assign;

if (__DEV__) {
var warned = false;
__spread = function() {
warning(
warned,
'React.__spread is deprecated and should not be used. Use ' +
'Object.assign directly or another helper function with similar ' +
'semantics. You may be seeing this warning due to your compiler. ' +
'See https://fb.me/react-spread-deprecation for more details.'
);
warned = true;
return Object.assign.apply(null, arguments);
};
export var __spread = __DEV__ ? Object.assign : spreadWithWarning;

export function createMixin(mixin) {
// Currently a noop. Will be used to validate and trace mixins.
return mixin;
}

var React = {
export var Children = {
map: ReactChildren.map,
forEach: ReactChildren.forEach,
count: ReactChildren.count,
toArray: ReactChildren.toArray,
only: onlyChild,
};

export {
ReactComponent as Component,
ReactDOMFactories as DOM,
ReactPropTypes as PropTypes,
ReactVersion as version,
};

// Modern
export var createClass = ReactClass.createClass;
export var isValidElement = ReactElement.isValidElement;

Children: {
map: ReactChildren.map,
forEach: ReactChildren.forEach,
count: ReactChildren.count,
toArray: ReactChildren.toArray,
only: onlyChild,
},
export default {
// Modern
Children: Children,

Component: ReactComponent,

createElement: createElement,
cloneElement: cloneElement,
isValidElement: ReactElement.isValidElement,
isValidElement: isValidElement,

// Classic

PropTypes: ReactPropTypes,
createClass: ReactClass.createClass,
createFactory: createFactory,
createMixin: function(mixin) {
// Currently a noop. Will be used to validate and trace mixins.
return mixin;
},
createMixin: createMixin,

// This looks DOM specific but these are actually isomorphic helpers
// since they are just generating DOM strings.
Expand All @@ -87,5 +167,3 @@ var React = {
// Deprecated hook for JSX spread, don't use this for anything.
__spread: __spread,
};

module.exports = React;
Loading

0 comments on commit b244c25

Please sign in to comment.