Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Remove react and add preact #13608

Merged
merged 12 commits into from
Aug 29, 2017
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,21 @@ require.config({
paths: {
"text" : "thirdparty/text/text",
"i18n" : "thirdparty/i18n/i18n",
"react" : "thirdparty/react",

// The file system implementation. Change this value to use different
// implementations (e.g. cloud-based storage).
"fileSystemImpl" : "filesystem/impls/appshell/AppshellFileSystem"
},
packages: [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably add preact as an node_module instead of inlining it to the thirdparty folder as we have been doing with new dependencies. (related to #12006)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petetnt Actually react is being replaced with preact to remove facebook dependencies due to the PATENT issues. But preact-compat uses prop-types which is by facebook and we do not use proptypes in the FileTreeView code, so I removed it manually from preact-compat. So only we are inlining it to the thirdparty folder.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, wasn't aware that compat uses prop-types package as-is

{
name: "thirdparty/preact",
location: "thirdparty/preact",
main: "preact-compat"
}
],
map: {
"*": {
"thirdparty/CodeMirror2": "thirdparty/CodeMirror",
"thirdparty/react": "react"
"thirdparty/CodeMirror2": "thirdparty/CodeMirror"
}
}
});
Expand Down
22 changes: 17 additions & 5 deletions src/project/FileTreeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
define(function (require, exports, module) {
"use strict";

var React = require("thirdparty/react"),
ReactDOM = require("thirdparty/react-dom"),
var React = require("thirdparty/preact"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should just find-and-replace all the React and ReactDOM mentions to Preact

ReactDOM = require("thirdparty/preact"),
Classnames = require("thirdparty/classnames"),
Immutable = require("thirdparty/immutable"),
_ = require("thirdparty/lodash"),
Expand Down Expand Up @@ -219,6 +219,7 @@ define(function (require, exports, module) {

var node = this.refs.name;
node.setSelectionRange(0, _getName(fullname, extension).length);
node.focus(); // set focus on the rename input
ViewUtils.scrollElementIntoView($("#project-files-container"), $(node), true);
},

Expand Down Expand Up @@ -480,6 +481,11 @@ define(function (require, exports, module) {
extension = LanguageManager.getCompoundFileExtension(fullname),
name = _getName(fullname, extension);

// React automatically wraps content in a span element whereas preact doesn't, so do it manually
if (name) {
name = DOM.span({}, name);
}

if (extension) {
extension = DOM.span({
className: "extension"
Expand Down Expand Up @@ -601,6 +607,7 @@ define(function (require, exports, module) {

var node = this.refs.name;
node.setSelectionRange(0, fullname.length);
node.focus(); // set focus on the rename input
ViewUtils.scrollElementIntoView($("#project-files-container"), $(node), true);
},

Expand Down Expand Up @@ -758,11 +765,16 @@ define(function (require, exports, module) {
parentPath: this.props.parentPath
});
} else {
// React automatically wraps content in a span element whereas preact doesn't, so do it manually
if (this.props.name) {
var name = DOM.span({}, this.props.name);
}

// Need to flatten the arguments because getIcons returns an array
var aArgs = _.flatten([{
href: "#",
className: directoryClasses
}, thickness, this.getIcons(), this.props.name]);
}, thickness, this.getIcons(), name]);
nameDisplay = DOM.a.apply(DOM.a, aArgs);
}

Expand Down Expand Up @@ -1035,11 +1047,11 @@ define(function (require, exports, module) {

return DOM.div(
null,
contents,
selectionBackground,
contextBackground,
extensionForSelection,
extensionForContext,
contents
extensionForContext
);
}
}));
Expand Down
2 changes: 1 addition & 1 deletion src/styles/jsTreeTheme.less
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/* (these are based on jsTree's default theme .css file, so they are not very LESS-like) */
@li-min-height: 23px;

.jstree ul, .jstree li { display:block; margin:0 0 0 0; padding:0 0 0 0; list-style-type:none; }
.jstree ul, .jstree li { display:block; margin:0 0 0 0; padding:0 0 0 0; list-style-type:none; z-index:1; }
.jstree li { display:block; min-height:@li-min-height; line-height:16px; white-space:nowrap; min-width:18px; }
.jstree-rtl li { margin-left:0; margin-right:18px; }
.jstree > ul > li { margin-left:0; }
Expand Down
8 changes: 8 additions & 0 deletions src/thirdparty/preact/events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
define (function(require, exports, module){
'use strict';

module.exports = `onKeyDown onKeyPress onKeyUp onFocus onBlur onClick onContextMenu onDoubleClick onDrag onDragEnd onDragEnter onDragExit onDragLeave onDragOver onDragStart onDrop onMouseDown onMouseEnter onMouseLeave onMouseMove onMouseOut onMouseOver onMouseUp onChange onInput onSubmit onTouchCancel onTouchEnd onTouchMove onTouchStart onLoad onError onAnimationStart onAnimationEnd onAnimationIteration onTransitionEnd`.split(' ').map(item => {
const event = item.replace('on', '');
return event.charAt(0).toLowerCase() + event.substr(1);
});
});
Loading