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

Commit

Permalink
General refactor, see details.
Browse files Browse the repository at this point in the history
Replace `var` with `const` where necessary.
Remove unnecessary semicolons in some places.
Add semicolons in some places.
General style refactorizations.
  • Loading branch information
Uman Shahzad committed Jun 9, 2017
1 parent 70b8d7c commit 4e6ea55
Show file tree
Hide file tree
Showing 22 changed files with 109 additions and 100 deletions.
31 changes: 17 additions & 14 deletions bin/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,40 @@ require('dotenv').load();
require('app-module-path').addPath(__dirname);
require('app-module-path').addPath('../src');

var fs = require('fs');
var path = require('path');
var webpackIsomorphicTools = require('webpack-isomorphic-tools');
var babelrc = fs.readFileSync('./.babelrc');
var rootDir = path.resolve(__dirname, '..');
var config;
const server = require('../src/server.js');
const fs = require('fs');
const path = require('path');
const piping = require('piping');
const webpackIsomorphicTools = require('webpack-isomorphic-tools');
const webpackIsomorphicToolsConfiguration = require('../webpack/isomorphic-tools-configuration');
const babelRegister = require('babel-register');

const babelrc = fs.readFileSync('./.babelrc');
const rootDir = path.resolve(__dirname, '..');

try {
config = JSON.parse(babelrc);
const config = JSON.parse(babelrc);
babelRegister(config);
} catch (err) {
console.error('==> ERROR: Error parsing your .babelrc.');
console.error(err);
}

require('babel-register')(config);

global.__CLIENT__ = false;
global.__SERVER__ = true;
global.__DEVELOPMENT__ = process.env.NODE_ENV !== 'production';

if (__DEVELOPMENT__) {
if (!require('piping')({
if (!piping({
hook: true,
ignore: /(\/\.|~$|\.json|\.scss$)/i
})) {
})) {
return;
}
}

global.webpack_isomorphic_tools = new webpackIsomorphicTools(require('../webpack/isomorphic-tools-configuration'))
global.webpack_isomorphic_tools = new webpackIsomorphicTools(webpackIsomorphicToolsConfiguration)
.development(process.env.NODE_ENV === 'development')
.server(rootDir, function() {
require('../src/server.js').default();
.server(rootDir, () => {
server.default();
});
11 changes: 7 additions & 4 deletions bin/server.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ require('dotenv').load();
require('app-module-path').addPath(__dirname);
require('app-module-path').addPath('../dist');

var webpackIsomorphicTools = require('webpack-isomorphic-tools');
var server = require('../dist/server.js');
var WebpackIsomorphicTools = require('webpack-isomorphic-tools');
var WebpackIsomorphicToolsConfiguration = require('../webpack/isomorphic-tools-configuration');
var path = require('path');

var rootDir = path.resolve(__dirname, '../dist');

global.__CLIENT__ = false;
global.__SERVER__ = true;
global.__DEVELOPMENT__ = process.env.NODE_ENV !== 'production';

global.webpack_isomorphic_tools = new webpackIsomorphicTools(require('../webpack/isomorphic-tools-configuration'))
global.webpack_isomorphic_tools = new WebpackIsomorphicTools(WebpackIsomorphicToolsConfiguration)
.development(__DEVELOPMENT__)
.server(rootDir, function() {
require('../dist/server.js').default();
.server(rootDir, () => {
server.default();
});
18 changes: 9 additions & 9 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var webpack = require('webpack');
const path = require('path');
const webpack = require('webpack');

module.exports = function(config) {
module.exports = (config) => {
config.set({

// base path that will be used to resolve all patterns (eg. files, exclude)
Expand All @@ -26,7 +27,7 @@ module.exports = function(config) {
'./node_modules/phantomjs-polyfill/bind-polyfill.js',
'./tests/polyfill/Event.js',
'./node_modules/Intl/locale-data/jsonp/en-US.js',
{pattern: 'static/images/*', watched: false, included: false, served: true},
{ pattern: 'static/images/*', watched: false, included: false, served: true },

// Actual tests here
'tests.webpack.js'
Expand All @@ -37,17 +38,16 @@ module.exports = function(config) {
],

proxies: {
'/images': __dirname + '/static/images',
'/images/': __dirname + '/static/images/',
'/images': path.join(__dirname, '/static/images'),
'/images/': path.join(__dirname, '/static/images/'),
},

proxyValidateSSL: false,

// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessors

preprocessors: {
'tests.webpack.js': [ 'webpack', 'sourcemap' ]
'tests.webpack.js': ['webpack', 'sourcemap']
},

webpack: {
Expand All @@ -72,9 +72,9 @@ module.exports = function(config) {
exclude: [/server/, /node_modules/, /tests/],
loader: 'babel'
},
{ test: /\.json$/, loader: 'json-loader'},
{ test: /\.json$/, loader: 'json-loader' },
{ test: /\.scss$/, loader: 'style!css?modules&importLoaders=2&sourceMap&localIdentName=[local]___[hash:base64:5]!autoprefixer?browsers=last 2 version!sass?outputStyle=expanded&sourceMap' },
{ test: /\.(jpe?g|png|gif|svg)$/, loader: 'url', query: {limit: 10240} }
{ test: /\.(jpe?g|png|gif|svg)$/, loader: 'url', query: { limit: 10240 } }
]
},

Expand Down
2 changes: 1 addition & 1 deletion src/components/FontSizeDropdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class FontSizeDropdown extends Component {
[type]: fontSize[type] + (changeFactor[type] * direction)
}
});
}
};

renderPopup() {
return (
Expand Down
2 changes: 1 addition & 1 deletion src/components/LazyLoad/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class LazyLoad extends Component {
}

return false;
}
};

render() {
const { isEnd, loadingComponent, endComponent } = this.props;
Expand Down
2 changes: 1 addition & 1 deletion src/components/NightModeToggle/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class NightModeToggle extends Component {
}

onToggle({ isNightMode: !isNightMode });
}
};

render() {
return (
Expand Down
6 changes: 3 additions & 3 deletions src/components/SearchAutocomplete/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ class SearchAutocomplete extends Component {
text: `<b>${match[0]}</b>`,
href: `/${match[1]}`
})).slice(0, 5);
}
};

suggest = (query) => {
const { lang } = this.props;

if (!query || ayahRegex.test(query)) return false;

return this.props.suggest(query, lang);
}
};

handleInputKeyDown = (event) => {
if (!(event.keyCode === 9 || event.keyCode === 40 || event.keyCode === 27)) {
Expand All @@ -104,7 +104,7 @@ class SearchAutocomplete extends Component {
return;
}
event.preventDefault();
}
};

handleItemKeyDown(event, item) {
const items = this.menu.getElementsByTagName('li');
Expand Down
2 changes: 1 addition & 1 deletion src/components/SearchInput/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class SearchInput extends Component {
}

return false;
}
};

render() {
const { showAutocomplete } = this.state;
Expand Down
6 changes: 3 additions & 3 deletions src/components/SmartBanner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ class SmartBanner extends Component {
parseAppId = (metaName) => {
const meta = window.document.querySelector(`meta[name="${metaName}"]`);
return /app-id=([^\s,]+)/.exec(meta.getAttribute('content'))[1];
}
};

hide = () => {
window.document.querySelector('html').classList.remove('smartbanner-show');
}
};

show = () => {
window.document.querySelector('html').classList.add('smartbanner-show');
}
};

close() {
this.hide();
Expand Down
4 changes: 1 addition & 3 deletions src/components/SurahInfo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ const style = require('./style.scss');
const SurahInfo = ({ chapter, info, isShowingSurahInfo, onClose }) => {
// So we don't need to load images and files unless needed
if (!isShowingSurahInfo) return <noscript />;
if (!info) {
return <Loader isActive />;
}
if (!info) return <Loader isActive />;

return (
<div className={`col-xs-12 ${style.container} chapter-info ${style.show}`}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/VersesDropdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class VersesDropdown extends Component {
{number}
</MenuItem>
);
}
};

renderMenu() {
const { chapter } = this.props;
Expand Down
14 changes: 7 additions & 7 deletions src/components/Word/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const CHAR_TYPE_SAJDAH = 'sajdah';
class Word extends Component {
buildTooltip = (word, tooltip) => {
let title;

if (word.charType === CHAR_TYPE_END) {
title = `Verse ${word.verseKey.split(':')[1]}`;
} else if (word.charType === CHAR_TYPE_WORD) {
Expand All @@ -21,17 +20,15 @@ class Word extends Component {
title = '';
}
return title;
}
};

handleWordPlay = () => {
const { word } = this.props;

if (word.audio) {
const audio = new Audio(word.audio.url); // eslint-disable-line

audio.play();
}
}
};

handleSegmentPlay = () => {
const { word, currentVerse, audioActions, audioPosition, isPlaying, isSearched } = this.props;
Expand All @@ -47,7 +44,7 @@ class Word extends Component {
audioActions.setAyah(word.verseKey);
audioActions.playCurrentWord({ word, position: audioPosition });
}
}
};

render() {
const { tooltip, word, currentVerse, isPlaying, audioPosition, useTextFont } = this.props;
Expand Down Expand Up @@ -84,7 +81,10 @@ class Word extends Component {
title={this.buildTooltip(word, tooltip)}
dangerouslySetInnerHTML={{ __html: text }}
/>
<small dangerouslySetInnerHTML={{ __html: spacer }} style={{ letterSpacing: -15 }} />
<small
dangerouslySetInnerHTML={{ __html: spacer }}
style={{ letterSpacing: -15 }}
/>
</span>
);
}
Expand Down
4 changes: 1 addition & 3 deletions src/containers/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ class App extends Component {
return (
<div
className={`embed-responsive embed-responsive-16by9 ${media.wrapperClass}`}
dangerouslySetInnerHTML={{
__html: media.content.body
}}
dangerouslySetInnerHTML={{ __html: media.content.body }}
/>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/containers/Contact/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Contact extends Component {
});
}
});
}
};

renderForm() {
return (
Expand Down
2 changes: 1 addition & 1 deletion src/containers/Search/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Search extends Component {
}

return true;
}
};

renderStatsBar() {
const { totalCount, totalPages, currentPage, query, perPage } = this.props;
Expand Down
9 changes: 8 additions & 1 deletion src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,14 @@ server.use((req, res, next) => {
});
}

const html = `<!doctype html>\n${ReactDOM.renderToString(<Html component={component} store={store} assets={webpack_isomorphic_tools.assets()} />)}`;
const html = `<!doctype html>
${ReactDOM.renderToString(
<Html
component={component}
store={store}
assets={webpack_isomorphic_tools.assets()}
/>
)}`;

return res.send(html);
})
Expand Down
Loading

0 comments on commit 4e6ea55

Please sign in to comment.