Skip to content

Commit

Permalink
feat: up to date dependencies , migrate react
Browse files Browse the repository at this point in the history
  • Loading branch information
hong4rc committed Apr 25, 2019
2 parents ac880da + 208a6c8 commit ad8d313
Show file tree
Hide file tree
Showing 12 changed files with 153 additions and 139 deletions.
8 changes: 4 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ var indexTemplate = _.template(indexFile);
*/

var prodDependencies = [
'<script src="//cdnjs.cloudflare.com/ajax/libs/es5-shim/4.1.1/es5-shim.min.js"></script>',
'<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>',
'<script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>'
'<script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.1.1/es5-shim.min.js"></script>',
'<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>',
'<script src="https://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>'
];

var devDependencies = [
Expand Down Expand Up @@ -232,7 +232,7 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-shell-spawn');
grunt.loadNpmTasks('grunt-jasmine-node');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-uglify-es');
grunt.loadNpmTasks('grunt-react');
grunt.loadNpmTasks('grunt-env');

Expand Down
22 changes: 13 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"browserify": "^13.0.0",
"contributor-faces": "^1.0.2",
"grunt": "^1.0.4",
"grunt-browserify": "^4.0.1",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-jshint": "~0.7.2",
"grunt-contrib-uglify": "~0.2.7",
"grunt-browserify": "^5.3.0",
"grunt-contrib-clean": "^2.0.0",
"grunt-contrib-jshint": "^2.1.0",
"grunt-contrib-uglify-es": "^3.3.0",
"grunt-env": "^0.4.4",
"grunt-hash": "~0.5.0",
"grunt-jasmine-node": "~0.1.0",
Expand All @@ -30,11 +30,15 @@
"prompt": "^1.0.0"
},
"dependencies": {
"backbone": "~1.1.2",
"flux": "^2.0.1",
"markdown": "~0.4.0",
"q": "~0.8.11",
"react": "^0.13.1",
"backbone": "^1.4.0",
"fbjs": "^1.0.0",
"flux": "^3.1.3",
"jquery": "^3.4.0",
"markdown": "^0.5.0",
"prop-types": "^15.7.2",
"q": "^1.5.1",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"underscore": "~1.4.3"
}
}
7 changes: 4 additions & 3 deletions src/js/app/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var Backbone = require('backbone');
var EventEmitter = require('events').EventEmitter;
var React = require('react');
var ReactDOM = require('react-dom');

var util = require('../util');
var intl = require('../intl');
Expand Down Expand Up @@ -251,7 +252,7 @@ var initDemo = function(sandbox) {
}
if (params.hasOwnProperty('STARTREACT')) {
/*
React.render(
ReactDOM.render(
React.createElement(CommandView, {}),
document.getElementById(params['STARTREACT'])
);*/
Expand Down Expand Up @@ -315,11 +316,11 @@ function CommandUI() {
el: $('#commandLineBar')
});

React.render(
ReactDOM.render(
React.createElement(MainHelperBarView),
document.getElementById('helperBarMount')
);
React.render(
ReactDOM.render(
React.createElement(
CommandHistoryView,
{ commandCollection: this.commandCollection }
Expand Down
7 changes: 4 additions & 3 deletions src/js/level/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
var Q = require('q');
var React = require('react');
var ReactDOM = require('react-dom');

var util = require('../util');
var Main = require('../app');
var intl = require('../intl');
var log = require('../log');

var React = require('react');
var Errors = require('../util/errors');
var Sandbox = require('../sandbox/').Sandbox;
var GlobalStateActions = require('../actions/GlobalStateActions');
Expand Down Expand Up @@ -139,7 +140,7 @@ var Level = Sandbox.extend({
parent: this
}
);
React.render(
ReactDOM.render(
this.levelToolbar,
document.getElementById('levelToolbarMount')
);
Expand Down Expand Up @@ -543,7 +544,7 @@ var Level = Sandbox.extend({
},

die: function() {
React.unmountComponentAtNode(
ReactDOM.unmountComponentAtNode(
document.getElementById('levelToolbarMount')
);

Expand Down
42 changes: 22 additions & 20 deletions src/js/react_views/CommandHistoryView.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
var React = require('react');
var PropTypes = require('prop-types');

var CommandView = require('../react_views/CommandView.jsx');
var Main = require('../app');
var React = require('react');

var _subscribeEvents = [
'add',
Expand All @@ -9,14 +11,9 @@ var _subscribeEvents = [
'all'
];

var CommandHistoryView = React.createClass({
class CommandHistoryView extends React.Component {

propTypes: {
// the backbone command model collection
commandCollection: React.PropTypes.object.isRequired
},

componentDidMount: function() {
componentDidMount() {
for (var i = 0; i < _subscribeEvents.length; i++) {
this.props.commandCollection.on(
_subscribeEvents[i],
Expand All @@ -27,24 +24,24 @@ var CommandHistoryView = React.createClass({

this.props.commandCollection.on('change', this.scrollDown, this);
Main.getEvents().on('commandScrollDown', this.scrollDown, this);
Main.getEvents().on('clearOldCommands', this.clearOldCommands, this);
},
Main.getEvents().on('clearOldCommands', () => this.clearOldCommands(), this);
}

componentWillUnmount: function() {
componentWillUnmount() {
for (var i = 0; i < _subscribeEvents.length; i++) {
this.props.commandCollection.off(
_subscribeEvents[i],
this.updateFromCollection,
this
);
}
},
}

updateFromCollection: function() {
updateFromCollection() {
this.forceUpdate();
},
}

render: function() {
render() {
var allCommands = [];
this.props.commandCollection.each(function(command, index) {
allCommands.push(
Expand All @@ -60,9 +57,9 @@ var CommandHistoryView = React.createClass({
{allCommands}
</div>
);
},
}

scrollDown: function() {
scrollDown() {
var cD = document.getElementById('commandDisplay');
var t = document.getElementById('terminal');

Expand All @@ -81,9 +78,9 @@ var CommandHistoryView = React.createClass({
if (shouldScroll) {
t.scrollTop = t.scrollHeight;
}
},
}

clearOldCommands: function() {
clearOldCommands() {
// go through and get rid of every command that is "processed" or done
var toDestroy = [];

Expand All @@ -100,6 +97,11 @@ var CommandHistoryView = React.createClass({
this.scrollDown();
}

});
}

CommandHistoryView.propTypes = {
// the backbone command model collection
commandCollection: PropTypes.object.isRequired
};

module.exports = CommandHistoryView;
64 changes: 29 additions & 35 deletions src/js/react_views/CommandView.jsx
Original file line number Diff line number Diff line change
@@ -1,66 +1,54 @@
var React = require('react');
var ReactDOM = require('react-dom');
var PropTypes = require('prop-types');

var reactUtil = require('../util/reactUtil');
var keyMirror = require('react/lib/keyMirror');
var keyMirror = require('fbjs/lib/keyMirror');

var STATUSES = keyMirror({
inqueue: null,
processing: null,
finished: null
});

var CommandView = React.createClass({
class CommandView extends React.Component{

propTypes: {
// the backbone command model
command: React.PropTypes.object.isRequired,
id: React.PropTypes.string,
},

componentDidMount: function() {
componentDidMount() {
this.props.command.on('change', this.updateStateFromModel, this);
this.props.command.on('destroy', this.onModelDestroy, this);
this.updateStateFromModel();
},
}

componentWillUnmount: function() {
componentWillUnmount() {
this.props.command.off('change', this.updateStateFromModel, this);
this.props.command.off('destroy', this.onModelDestroy, this);
},

onModelDestroy: function() {
if (!this.isMounted()) {
return;
}
if (!this.getDOMNode) {
// WTF -- only happens in casperjs tests weirdly
console.error('this.getDOMNode not a function?');
return;
}
}

React.unmountComponentAtNode(this.getDOMNode().parentNode);
},
onModelDestroy() {
ReactDOM.unmountComponentAtNode(ReactDOM.findDOMNode(this).parentNode);
}

updateStateFromModel: function() {
updateStateFromModel() {
var commandJSON = this.props.command.toJSON();
this.setState({
status: commandJSON.status,
rawStr: commandJSON.rawStr,
warnings: commandJSON.warnings,
result: commandJSON.result
});
},
}

getInitialState: function() {
return {
constructor(props, context) {
super(props, context);
this.state = {
status: STATUSES.inqueue,
rawStr: 'git commit',
warnings: [],
result: ''
};
},
}

render: function() {
render() {
var commandClass = reactUtil.joinClasses([
this.state.status,
'commandLine',
Expand Down Expand Up @@ -89,9 +77,9 @@ var CommandView = React.createClass({
</div>
</div>
);
},
}

renderResult: function() {
renderResult() {
if (!this.state.result) {
return null;
}
Expand Down Expand Up @@ -126,9 +114,9 @@ var CommandView = React.createClass({
{result}
</div>
);
},
}

renderFormattedWarnings: function() {
renderFormattedWarnings() {
var warnings = this.state.warnings;
var result = [];
for (var i = 0; i < warnings.length; i++) {
Expand All @@ -141,6 +129,12 @@ var CommandView = React.createClass({
}
return result;
}
});
};

CommandView.propTypes = {
// the backbone command model
command: PropTypes.object.isRequired,
id: PropTypes.string,
};

module.exports = CommandView;
27 changes: 14 additions & 13 deletions src/js/react_views/CommandsHelperBarView.jsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
var React = require('react');
var PropTypes = require('prop-types');
var HelperBarView = require('../react_views/HelperBarView.jsx');
var Main = require('../app');
var React = require('react');

var log = require('../log');

var CommandsHelperBarView = React.createClass({

propTypes: {
shown: React.PropTypes.bool.isRequired,
onExit: React.PropTypes.func.isRequired
},
class CommandsHelperBarView extends React.Component {

render: function() {
render() {
return (
<HelperBarView
items={this.getItems()}
shown={this.props.shown}
/>
);
},
}

fireCommand: function(command) {
fireCommand(command) {
log.viewInteracted('commandHelperBar');
Main.getEventBaton().trigger('commandSubmitted', command);
},
}

getItems: function() {
getItems() {
return [{
text: 'Levels',
onClick: function() {
Expand Down Expand Up @@ -64,6 +60,11 @@ var CommandsHelperBarView = React.createClass({
}];
}

});
};

CommandsHelperBarView.propTypes = {
shown: PropTypes.bool.isRequired,
onExit: PropTypes.func.isRequired
};

module.exports = CommandsHelperBarView;
Loading

0 comments on commit ad8d313

Please sign in to comment.