Skip to content

Commit

Permalink
Reorganize Src Files for Isomorphic React Package
Browse files Browse the repository at this point in the history
The new folder structure is organized around major packages that are expected to ship separately in some form.

`/isomorphic`

I moved classic/modern and children utils into a directory called "isomorphic" with the main export being ReactIsomorphic. This will eventually become the "react" package.

This includes all the dependencies that you might need to create a component without dependencies on the renderer/reconciler.

The rest moves into decoupled renderers.

`/renderers/dom/client` - This is the main renderer for DOM.

`/renderers/dom/server` - This is the server-side renderer for HTML strings.

`/addons` and `/test` - Same as before for now.

You're not supposed to take on a dependency inside another package.

Shared code is organized into a "shared" directory which is intended to support all the packages in that subdirectory. Meaning that once we swap to CommonJS modules, the only time you should use `..` is to target `../shared/` or `../../shared`.

E.g. `/shared/` is common utils that are used by everything.

`/renderers/shared/` is code that is shared by all renderers, such as the main reconciliation algorithm.

Shared code will likely be copied into each package rather than referenced. This allow us to have separate state and allow inlining and deadcode elimination.
  • Loading branch information
sebmarkbage committed May 16, 2015
1 parent bea5a57 commit 0b063f8
Show file tree
Hide file tree
Showing 261 changed files with 138 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# We can probably lint these later but not important at this point
src/vendor
src/shared/vendor
# eslint uses JSX* node types to determine if using JSX. esprima-fb still uses
# XJS* nodes. When we fix that (https://github.com/facebook/esprima/pull/85) we
# can enable linting the tests and fix those errors.
Expand Down
2 changes: 1 addition & 1 deletion grunt/config/jsx.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var assign = require('../../src/stubs/Object.assign');
var assign = require('../../src/shared/stubs/Object.assign');
var grunt = require('grunt');

var rootIDs = [
Expand Down
2 changes: 1 addition & 1 deletion grunt/tasks/version-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var reactVersionExp = /\bReact\.version\s*=\s*['"]([^'"]+)['"];/;

module.exports = function() {
var reactVersion = reactVersionExp.exec(
grunt.file.read('./src/browser/ui/React.js')
grunt.file.read('./src/React.js')
)[1];
var npmReactVersion = grunt.file.readJSON('./npm-react/package.json').version;
var reactToolsVersion = grunt.config.data.pkg.version;
Expand Down
2 changes: 1 addition & 1 deletion jest/preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var tsPreprocessor = require('./ts-preprocessor');

var defaultLibraries = [
require.resolve('./jest.d.ts'),
require.resolve('../src/modern/class/React.d.ts')
require.resolve('../src/isomorphic/modern/class/React.d.ts')
];

var ts = tsPreprocessor(defaultLibraries);
Expand Down
28 changes: 28 additions & 0 deletions src/React.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright 2013-2015, 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 ReactDOMClient = require('ReactDOMClient');
var ReactDOMServer = require('ReactDOMServer');
var ReactIsomorphic = require('ReactIsomorphic');

var assign = require('Object.assign');

var React = {};

assign(React, ReactIsomorphic);
assign(React, ReactDOMClient);
assign(React, ReactDOMServer);

React.version = '0.14.0-alpha1';

module.exports = React;
File renamed without changes.
70 changes: 70 additions & 0 deletions src/isomorphic/ReactIsomorphic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* Copyright 2013-2015, 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 ReactIsomorphic
*/

'use strict';

var ReactChildren = require('ReactChildren');
var ReactComponent = require('ReactComponent');
var ReactClass = require('ReactClass');
var ReactDOM = require('ReactDOM');
var ReactElement = require('ReactElement');
var ReactElementValidator = require('ReactElementValidator');
var ReactPropTypes = require('ReactPropTypes');

var assign = require('Object.assign');
var onlyChild = require('onlyChild');

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

if (__DEV__) {
createElement = ReactElementValidator.createElement;
createFactory = ReactElementValidator.createFactory;
cloneElement = ReactElementValidator.cloneElement;
}

var React = {

// Modern

Children: {
map: ReactChildren.map,
forEach: ReactChildren.forEach,
count: ReactChildren.count,
only: onlyChild
},

Component: ReactComponent,

createElement: createElement,
cloneElement: cloneElement,
isValidElement: ReactElement.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;
},

// This looks DOM specific but these are actually isomorphic helpers
// since they are just generating DOM strings.
DOM: ReactDOM,

// Hook for JSX spread, don't use this for anything else.
__spread: assign
};

module.exports = React;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
49 changes: 2 additions & 47 deletions src/browser/ui/React.js → src/renderers/dom/ReactDOMClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,77 +6,34 @@
* 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
* @providesModule ReactDOMClient
*/

/* globals __REACT_DEVTOOLS_GLOBAL_HOOK__*/

'use strict';

var ReactChildren = require('ReactChildren');
var ReactComponent = require('ReactComponent');
var ReactClass = require('ReactClass');
var ReactCurrentOwner = require('ReactCurrentOwner');
var ReactElement = require('ReactElement');
var ReactElementValidator = require('ReactElementValidator');
var ReactDOM = require('ReactDOM');
var ReactDOMTextComponent = require('ReactDOMTextComponent');
var ReactDefaultInjection = require('ReactDefaultInjection');
var ReactInstanceHandles = require('ReactInstanceHandles');
var ReactMount = require('ReactMount');
var ReactPerf = require('ReactPerf');
var ReactPropTypes = require('ReactPropTypes');
var ReactReconciler = require('ReactReconciler');
var ReactServerRendering = require('ReactServerRendering');

var assign = require('Object.assign');
var findDOMNode = require('findDOMNode');
var onlyChild = require('onlyChild');
var warning = require('warning');

ReactDefaultInjection.inject();

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

if (__DEV__) {
createElement = ReactElementValidator.createElement;
createFactory = ReactElementValidator.createFactory;
cloneElement = ReactElementValidator.cloneElement;
}

var render = ReactPerf.measure('React', 'render', ReactMount.render);

var React = {
Children: {
map: ReactChildren.map,
forEach: ReactChildren.forEach,
count: ReactChildren.count,
only: onlyChild
},
Component: ReactComponent,
DOM: ReactDOM,
PropTypes: ReactPropTypes,
createClass: ReactClass.createClass,
createElement: createElement,
cloneElement: cloneElement,
createFactory: createFactory,
createMixin: function(mixin) {
// Currently a noop. Will be used to validate and trace mixins.
return mixin;
},
constructAndRenderComponent: ReactMount.constructAndRenderComponent,
constructAndRenderComponentByID: ReactMount.constructAndRenderComponentByID,
findDOMNode: findDOMNode,
render: render,
renderToString: ReactServerRendering.renderToString,
renderToStaticMarkup: ReactServerRendering.renderToStaticMarkup,
unmountComponentAtNode: ReactMount.unmountComponentAtNode,
isValidElement: ReactElement.isValidElement,

// Hook for JSX spread, don't use this for anything else.
__spread: assign
unmountComponentAtNode: ReactMount.unmountComponentAtNode
};

// Inject the runtime into a devtools global hook regardless of browser.
Expand Down Expand Up @@ -150,6 +107,4 @@ if (__DEV__) {
}
}

React.version = '0.14.0-alpha1';

module.exports = React;
24 changes: 24 additions & 0 deletions src/renderers/dom/ReactDOMServer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright 2013-2015, 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 ReactDOMServer
*/

'use strict';

var ReactDefaultInjection = require('ReactDefaultInjection');
var ReactServerRendering = require('ReactServerRendering');

ReactDefaultInjection.inject();

var ReactDOMServer = {
renderToString: ReactServerRendering.renderToString,
renderToStaticMarkup: ReactServerRendering.renderToStaticMarkup
};

module.exports = ReactDOMServer;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,17 @@ function autoGenerateWrapperClass(type) {
});
}

var alreadyInjected = false;

function inject() {
if (alreadyInjected) {
// TODO: This is currently true because these injections are shared between
// the client and the server package. They should be built independently
// and not share any injection state. Then this problem will be solved.
return;
}
alreadyInjected = true;

ReactInjection.EventEmitter.injectReactEventListener(
ReactEventListener
);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 0b063f8

Please sign in to comment.