Skip to content

Commit 32fd92b

Browse files
committed
Reorganize Src Files for Isomorphic React Package
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.
1 parent bea5a57 commit 32fd92b

File tree

261 files changed

+138
-51
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

261 files changed

+138
-51
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# We can probably lint these later but not important at this point
2-
src/vendor
2+
src/shared/vendor
33
# eslint uses JSX* node types to determine if using JSX. esprima-fb still uses
44
# XJS* nodes. When we fix that (https://github.com/facebook/esprima/pull/85) we
55
# can enable linting the tests and fix those errors.

grunt/config/jsx.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
var assign = require('../../src/stubs/Object.assign');
3+
var assign = require('../../src/shared/stubs/Object.assign');
44
var grunt = require('grunt');
55

66
var rootIDs = [

grunt/tasks/version-check.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var reactVersionExp = /\bReact\.version\s*=\s*['"]([^'"]+)['"];/;
1010

1111
module.exports = function() {
1212
var reactVersion = reactVersionExp.exec(
13-
grunt.file.read('./src/browser/ui/React.js')
13+
grunt.file.read('./src/React.js')
1414
)[1];
1515
var npmReactVersion = grunt.file.readJSON('./npm-react/package.json').version;
1616
var reactToolsVersion = grunt.config.data.pkg.version;

jest/preprocessor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var tsPreprocessor = require('./ts-preprocessor');
77

88
var defaultLibraries = [
99
require.resolve('./jest.d.ts'),
10-
require.resolve('../src/modern/class/React.d.ts')
10+
require.resolve('../src/isomorphic/modern/class/React.d.ts')
1111
];
1212

1313
var ts = tsPreprocessor(defaultLibraries);

src/React.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Copyright 2013-2015, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* @providesModule React
10+
*/
11+
12+
'use strict';
13+
14+
var ReactDOMClient = require('ReactDOMClient');
15+
var ReactDOMServer = require('ReactDOMServer');
16+
var ReactIsomorphic = require('ReactIsomorphic');
17+
18+
var assign = require('Object.assign');
19+
20+
var React = {};
21+
22+
assign(React, ReactIsomorphic);
23+
assign(React, ReactDOMClient);
24+
assign(React, ReactDOMServer);
25+
26+
React.version = '0.14.0-alpha1';
27+
28+
module.exports = React;
File renamed without changes.

src/isomorphic/ReactIsomorphic.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* Copyright 2013-2015, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* @providesModule ReactIsomorphic
10+
*/
11+
12+
'use strict';
13+
14+
var ReactChildren = require('ReactChildren');
15+
var ReactComponent = require('ReactComponent');
16+
var ReactClass = require('ReactClass');
17+
var ReactDOM = require('ReactDOM');
18+
var ReactElement = require('ReactElement');
19+
var ReactElementValidator = require('ReactElementValidator');
20+
var ReactPropTypes = require('ReactPropTypes');
21+
22+
var assign = require('Object.assign');
23+
var onlyChild = require('onlyChild');
24+
25+
var createElement = ReactElement.createElement;
26+
var createFactory = ReactElement.createFactory;
27+
var cloneElement = ReactElement.cloneElement;
28+
29+
if (__DEV__) {
30+
createElement = ReactElementValidator.createElement;
31+
createFactory = ReactElementValidator.createFactory;
32+
cloneElement = ReactElementValidator.cloneElement;
33+
}
34+
35+
var React = {
36+
37+
// Modern
38+
39+
Children: {
40+
map: ReactChildren.map,
41+
forEach: ReactChildren.forEach,
42+
count: ReactChildren.count,
43+
only: onlyChild
44+
},
45+
46+
Component: ReactComponent,
47+
48+
createElement: createElement,
49+
cloneElement: cloneElement,
50+
isValidElement: ReactElement.isValidElement,
51+
52+
// Classic
53+
54+
PropTypes: ReactPropTypes,
55+
createClass: ReactClass.createClass,
56+
createFactory: createFactory,
57+
createMixin: function(mixin) {
58+
// Currently a noop. Will be used to validate and trace mixins.
59+
return mixin;
60+
},
61+
62+
// This looks DOM specific but these are actually isomorphic helpers
63+
// since they are just generating DOM strings.
64+
DOM: ReactDOM,
65+
66+
// Hook for JSX spread, don't use this for anything else.
67+
__spread: assign
68+
};
69+
70+
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.

src/browser/ui/React.js renamed to src/renderers/dom/ReactDOMClient.js

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,77 +6,34 @@
66
* LICENSE file in the root directory of this source tree. An additional grant
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*
9-
* @providesModule React
9+
* @providesModule ReactDOMClient
1010
*/
1111

1212
/* globals __REACT_DEVTOOLS_GLOBAL_HOOK__*/
1313

1414
'use strict';
1515

16-
var ReactChildren = require('ReactChildren');
17-
var ReactComponent = require('ReactComponent');
18-
var ReactClass = require('ReactClass');
1916
var ReactCurrentOwner = require('ReactCurrentOwner');
20-
var ReactElement = require('ReactElement');
21-
var ReactElementValidator = require('ReactElementValidator');
22-
var ReactDOM = require('ReactDOM');
2317
var ReactDOMTextComponent = require('ReactDOMTextComponent');
2418
var ReactDefaultInjection = require('ReactDefaultInjection');
2519
var ReactInstanceHandles = require('ReactInstanceHandles');
2620
var ReactMount = require('ReactMount');
2721
var ReactPerf = require('ReactPerf');
28-
var ReactPropTypes = require('ReactPropTypes');
2922
var ReactReconciler = require('ReactReconciler');
30-
var ReactServerRendering = require('ReactServerRendering');
3123

32-
var assign = require('Object.assign');
3324
var findDOMNode = require('findDOMNode');
34-
var onlyChild = require('onlyChild');
3525
var warning = require('warning');
3626

3727
ReactDefaultInjection.inject();
3828

39-
var createElement = ReactElement.createElement;
40-
var createFactory = ReactElement.createFactory;
41-
var cloneElement = ReactElement.cloneElement;
42-
43-
if (__DEV__) {
44-
createElement = ReactElementValidator.createElement;
45-
createFactory = ReactElementValidator.createFactory;
46-
cloneElement = ReactElementValidator.cloneElement;
47-
}
48-
4929
var render = ReactPerf.measure('React', 'render', ReactMount.render);
5030

5131
var React = {
52-
Children: {
53-
map: ReactChildren.map,
54-
forEach: ReactChildren.forEach,
55-
count: ReactChildren.count,
56-
only: onlyChild
57-
},
58-
Component: ReactComponent,
59-
DOM: ReactDOM,
60-
PropTypes: ReactPropTypes,
61-
createClass: ReactClass.createClass,
62-
createElement: createElement,
63-
cloneElement: cloneElement,
64-
createFactory: createFactory,
65-
createMixin: function(mixin) {
66-
// Currently a noop. Will be used to validate and trace mixins.
67-
return mixin;
68-
},
6932
constructAndRenderComponent: ReactMount.constructAndRenderComponent,
7033
constructAndRenderComponentByID: ReactMount.constructAndRenderComponentByID,
7134
findDOMNode: findDOMNode,
7235
render: render,
73-
renderToString: ReactServerRendering.renderToString,
74-
renderToStaticMarkup: ReactServerRendering.renderToStaticMarkup,
75-
unmountComponentAtNode: ReactMount.unmountComponentAtNode,
76-
isValidElement: ReactElement.isValidElement,
77-
78-
// Hook for JSX spread, don't use this for anything else.
79-
__spread: assign
36+
unmountComponentAtNode: ReactMount.unmountComponentAtNode
8037
};
8138

8239
// Inject the runtime into a devtools global hook regardless of browser.
@@ -150,6 +107,4 @@ if (__DEV__) {
150107
}
151108
}
152109

153-
React.version = '0.14.0-alpha1';
154-
155110
module.exports = React;

src/renderers/dom/ReactDOMServer.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Copyright 2013-2015, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* @providesModule ReactDOMServer
10+
*/
11+
12+
'use strict';
13+
14+
var ReactDefaultInjection = require('ReactDefaultInjection');
15+
var ReactServerRendering = require('ReactServerRendering');
16+
17+
ReactDefaultInjection.inject();
18+
19+
var ReactDOMServer = {
20+
renderToString: ReactServerRendering.renderToString,
21+
renderToStaticMarkup: ReactServerRendering.renderToStaticMarkup
22+
};
23+
24+
module.exports = ReactDOMServer;
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/browser/ui/ReactDefaultInjection.js renamed to src/renderers/dom/shared/ReactDefaultInjection.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,17 @@ function autoGenerateWrapperClass(type) {
6666
});
6767
}
6868

69+
var alreadyInjected = false;
70+
6971
function inject() {
72+
if (alreadyInjected) {
73+
// TODO: This is currently true because these injections are shared between
74+
// the client and the server package. They should be built independently
75+
// and not share any injection state. Then this problem will be solved.
76+
return;
77+
}
78+
alreadyInjected = true;
79+
7080
ReactInjection.EventEmitter.injectReactEventListener(
7181
ReactEventListener
7282
);
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 commit comments

Comments
 (0)