fixed non-optimal function declarations

This commit is contained in:
Nikhil Sharma 2019-03-17 14:49:45 +05:30 committed by GitHub
parent 3527568955
commit 52291c69f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -28,6 +28,22 @@ class Nav extends React.PureComponent {
this.clearHideTimeout = this.clearHideTimeout.bind(this); this.clearHideTimeout = this.clearHideTimeout.bind(this);
this.handleClick = this.handleClick.bind(this); this.handleClick = this.handleClick.bind(this);
this.handleClickOutside = this.handleClickOutside.bind(this); this.handleClickOutside = this.handleClickOutside.bind(this);
this.handleSave = this.handleSave.bind(this);
this.handleNew = this.handleNew.bind(this);
this.handleDuplicate = this.handleDuplicate.bind(this);
this.handleShare = this.handleShare.bind(this);
this.handleDownload = this.handleDownload.bind(this);
this.handleFind = this.handleFind.bind(this);
this.handleAddFile = this.handleAddFile.bind(this);
this.handleAddFolder = this.handleAddFolder.bind(this);
this.handleFindNext = this.handleFindNext.bind(this);
this.handleRun = this.handleRun.bind(this);
this.handleFindPrevious = this.handleFindPrevious.bind(this);
this.handleStop = this.handleStop.bind(this);
this.handleStartAccessible = this.handleStartAccessible.apply(this);
this.handleStopAccessible = this.handleStopAccessible.bind(this);
this.handleKeyboardShortcuts = this.handleKeyboardShortcuts.bind(this);
this.handleLogout = this.handleLogout.bind(this);
} }
componentWillMount() { componentWillMount() {
@ -52,6 +68,95 @@ class Nav extends React.PureComponent {
this.handleClickOutside(); this.handleClickOutside();
} }
handleNew() {
if (!this.props.unsavedChanges) {
this.props.newProject();
} else if (this.props.warnIfUnsavedChanges()) {
this.props.newProject();
}
this.setDropdown('none');
}
handleSave() {
if (this.props.user.authenticated) {
this.props.saveProject(this.props.cmController.getContent());
} else {
this.props.showErrorModal('forceAuthentication');
}
this.setDropdown('none');
}
handleFind() {
this.props.cmController.showFind();
this.setDropdown('none');
}
handleFindNext() {
this.props.cmController.findNext();
this.setDropdown('none');
}
handleFindPrevious() {
this.props.cmController.findPrev();
this.setDropdown('none');
}
handleAddFile() {
this.props.newFile();
this.setDropdown('none');
}
handleAddFolder() {
this.props.newFolder();
this.setDropdown('none');
}
handleRun() {
this.props.startSketch();
this.setDropdown('none');
}
handleStop() {
this.props.stopSketch();
this.setDropdown('none');
}
handleStartAccessible() {
this.props.setAllAccessibleOutput(true);
this.setDropdown('none');
}
handleStopAccessible() {
this.props.setAllAccessibleOutput(false);
this.setDropdown('none');
}
handleKeyboardShortcuts() {
this.props.showKeyboardShortcutModal();
this.setDropdown('none');
}
handleLogout() {
this.props.logoutUser();
this.setDropdown('none');
}
handleDownload() {
this.props.autosaveProject();
this.props.exportProjectAsZip(this.props.project.id);
this.setDropdown('none');
}
handleDuplicate() {
this.props.cloneProject();
this.setDropdown('none');
}
handleShare() {
this.props.showShareModal();
this.setDropdown('none');
}
handleClickOutside() { handleClickOutside() {
this.setState({ this.setState({
dropdownOpen: 'none' dropdownOpen: 'none'
@ -138,14 +243,7 @@ class Nav extends React.PureComponent {
</button> </button>
<li className="nav__dropdown-item"> <li className="nav__dropdown-item">
<button <button
onClick={() => { onClick={this.handleNew}
if (!this.props.unsavedChanges) {
this.props.newProject();
} else if (this.props.warnIfUnsavedChanges()) {
this.props.newProject();
}
this.setDropdown('none');
}}
onFocus={this.handleFocus.bind(this, 'file')} onFocus={this.handleFocus.bind(this, 'file')}
onBlur={this.handleBlur} onBlur={this.handleBlur}
> >
@ -155,14 +253,7 @@ class Nav extends React.PureComponent {
{ __process.env.LOGIN_ENABLED && (!this.props.project.owner || this.isUserOwner()) && { __process.env.LOGIN_ENABLED && (!this.props.project.owner || this.isUserOwner()) &&
<li className="nav__dropdown-item"> <li className="nav__dropdown-item">
<button <button
onClick={() => { onClick={this.handleSave}
if (this.props.user.authenticated) {
this.props.saveProject(this.props.cmController.getContent());
} else {
this.props.showErrorModal('forceAuthentication');
}
this.setDropdown('none');
}}
onFocus={this.handleFocus.bind(this, 'file')} onFocus={this.handleFocus.bind(this, 'file')}
onBlur={this.handleBlur} onBlur={this.handleBlur}
> >
@ -173,10 +264,7 @@ class Nav extends React.PureComponent {
{ this.props.project.id && this.props.user.authenticated && { this.props.project.id && this.props.user.authenticated &&
<li className="nav__dropdown-item"> <li className="nav__dropdown-item">
<button <button
onClick={() => { onClick={this.handleDuplicate}
this.props.cloneProject();
this.setDropdown('none');
}}
onFocus={this.handleFocus.bind(this, 'file')} onFocus={this.handleFocus.bind(this, 'file')}
onBlur={this.handleBlur} onBlur={this.handleBlur}
> >
@ -186,10 +274,7 @@ class Nav extends React.PureComponent {
{ this.props.project.id && { this.props.project.id &&
<li className="nav__dropdown-item"> <li className="nav__dropdown-item">
<button <button
onClick={() => { onClick={this.handleShare}
this.props.showShareModal();
this.setDropdown('none');
}}
onFocus={this.handleFocus.bind(this, 'file')} onFocus={this.handleFocus.bind(this, 'file')}
onBlur={this.handleBlur} onBlur={this.handleBlur}
> >
@ -199,11 +284,7 @@ class Nav extends React.PureComponent {
{ this.props.project.id && { this.props.project.id &&
<li className="nav__dropdown-item"> <li className="nav__dropdown-item">
<button <button
onClick={() => { onClick={this.handleDownload}
this.props.autosaveProject();
this.props.exportProjectAsZip(this.props.project.id);
this.setDropdown('none');
}}
onFocus={this.handleFocus.bind(this, 'file')} onFocus={this.handleFocus.bind(this, 'file')}
onBlur={this.handleBlur} onBlur={this.handleBlur}
> >
@ -266,10 +347,7 @@ class Nav extends React.PureComponent {
</li> </li>
<li className="nav__dropdown-item"> <li className="nav__dropdown-item">
<button <button
onClick={() => { onClick={this.handleFind}
this.props.cmController.showFind();
this.setDropdown('none');
}}
onFocus={this.handleFocus.bind(this, 'edit')} onFocus={this.handleFocus.bind(this, 'edit')}
onBlur={this.handleBlur} onBlur={this.handleBlur}
> >
@ -279,10 +357,7 @@ class Nav extends React.PureComponent {
</li> </li>
<li className="nav__dropdown-item"> <li className="nav__dropdown-item">
<button <button
onClick={() => { onClick={this.handleFindNext}
this.props.cmController.findNext();
this.setDropdown('none');
}}
onFocus={this.handleFocus.bind(this, 'edit')} onFocus={this.handleFocus.bind(this, 'edit')}
onBlur={this.handleBlur} onBlur={this.handleBlur}
> >
@ -292,10 +367,7 @@ class Nav extends React.PureComponent {
</li> </li>
<li className="nav__dropdown-item"> <li className="nav__dropdown-item">
<button <button
onClick={() => { onClick={this.handleFindPrevious}
this.props.cmController.findPrev();
this.setDropdown('none');
}}
onFocus={this.handleFocus.bind(this, 'edit')} onFocus={this.handleFocus.bind(this, 'edit')}
onBlur={this.handleBlur} onBlur={this.handleBlur}
> >
@ -324,10 +396,7 @@ class Nav extends React.PureComponent {
</button> </button>
<li className="nav__dropdown-item"> <li className="nav__dropdown-item">
<button <button
onClick={() => { onClick={this.handleAddFile}
this.props.newFile();
this.setDropdown('none');
}}
onFocus={this.handleFocus.bind(this, 'sketch')} onFocus={this.handleFocus.bind(this, 'sketch')}
onBlur={this.handleBlur} onBlur={this.handleBlur}
> >
@ -336,10 +405,7 @@ class Nav extends React.PureComponent {
</li> </li>
<li className="nav__dropdown-item"> <li className="nav__dropdown-item">
<button <button
onClick={() => { onClick={this.handleAddFolder}
this.props.newFolder();
this.setDropdown('none');
}}
onFocus={this.handleFocus.bind(this, 'sketch')} onFocus={this.handleFocus.bind(this, 'sketch')}
onBlur={this.handleBlur} onBlur={this.handleBlur}
> >
@ -348,10 +414,7 @@ class Nav extends React.PureComponent {
</li> </li>
<li className="nav__dropdown-item"> <li className="nav__dropdown-item">
<button <button
onClick={() => { onClick={this.handleRun}
this.props.startSketch();
this.setDropdown('none');
}}
onFocus={this.handleFocus.bind(this, 'sketch')} onFocus={this.handleFocus.bind(this, 'sketch')}
onBlur={this.handleBlur} onBlur={this.handleBlur}
> >
@ -361,10 +424,7 @@ class Nav extends React.PureComponent {
</li> </li>
<li className="nav__dropdown-item"> <li className="nav__dropdown-item">
<button <button
onClick={() => { onClick={this.handleStop}
this.props.stopSketch();
this.setDropdown('none');
}}
onFocus={this.handleFocus.bind(this, 'sketch')} onFocus={this.handleFocus.bind(this, 'sketch')}
onBlur={this.handleBlur} onBlur={this.handleBlur}
> >
@ -374,10 +434,7 @@ class Nav extends React.PureComponent {
</li> </li>
<li className="nav__dropdown-item"> <li className="nav__dropdown-item">
<button <button
onClick={() => { onClick={this.handleStartAccessible}
this.props.setAllAccessibleOutput(true);
this.setDropdown('none');
}}
onFocus={this.handleFocus.bind(this, 'sketch')} onFocus={this.handleFocus.bind(this, 'sketch')}
onBlur={this.handleBlur} onBlur={this.handleBlur}
> >
@ -387,10 +444,7 @@ class Nav extends React.PureComponent {
</li> </li>
<li className="nav__dropdown-item"> <li className="nav__dropdown-item">
<button <button
onClick={() => { onClick={this.handleStopAccessible}
this.props.setAllAccessibleOutput(false);
this.setDropdown('none');
}}
onFocus={this.handleFocus.bind(this, 'sketch')} onFocus={this.handleFocus.bind(this, 'sketch')}
onBlur={this.handleBlur} onBlur={this.handleBlur}
> >
@ -421,10 +475,7 @@ class Nav extends React.PureComponent {
<button <button
onFocus={this.handleFocus.bind(this, 'help')} onFocus={this.handleFocus.bind(this, 'help')}
onBlur={this.handleBlur} onBlur={this.handleBlur}
onClick={() => { onClick={this.handleKeyboardShortcuts}
this.props.showKeyboardShortcutModal();
this.setDropdown('none');
}}
> >
Keyboard Shortcuts Keyboard Shortcuts
</button> </button>
@ -529,10 +580,7 @@ class Nav extends React.PureComponent {
</li> </li>
<li className="nav__dropdown-item"> <li className="nav__dropdown-item">
<button <button
onClick={() => { onClick={this.handleLogout}
this.props.logoutUser();
this.setDropdown('none');
}}
onFocus={this.handleFocus.bind(this, 'account')} onFocus={this.handleFocus.bind(this, 'account')}
onBlur={this.handleBlur} onBlur={this.handleBlur}
> >