summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrr- <rr-@sakuya.pl>2016-05-20 23:10:45 +0200
committerrr- <rr-@sakuya.pl>2016-05-21 00:08:43 +0200
commit249d6073c03f68637d867147e85f0bf76acc5bdb (patch)
treee7db76a10ef655b66e24655707b75096dc8fb8db
parent69fe8ec31a0827eda913e55ca464228168ffcaf1 (diff)
client/build: remove babel when not transpiling
-rw-r--r--client/.jscsrc6
-rw-r--r--client/build.js7
-rw-r--r--client/js/controllers/users_controller.js22
-rw-r--r--client/js/util/polyfill.js30
4 files changed, 21 insertions, 44 deletions
diff --git a/client/.jscsrc b/client/.jscsrc
index c12b28d..46218cd 100644
--- a/client/.jscsrc
+++ b/client/.jscsrc
@@ -1,5 +1,5 @@
{
- "preset": "google",
- "fileExtensions": [".js", "jscs"],
- "validateIndentation": 4,
+ preset: "google",
+ fileExtensions: [".js", "jscs"],
+ validateIndentation: 4,
}
diff --git a/client/build.js b/client/build.js
index 9b19337..fbf378d 100644
--- a/client/build.js
+++ b/client/build.js
@@ -117,7 +117,6 @@ function writeJsBundle(b, path, message, compress) {
}
function bundleJs(config) {
- const babelify = require('babelify');
const browserify = require('browserify');
const external = [
'lodash',
@@ -126,7 +125,6 @@ function bundleJs(config) {
'js-cookie',
'page',
'nprogress',
- 'babel-polyfill',
];
glob('./js/**/*.js', {}, (er, files) => {
if (!process.argv.includes('--no-vendor-js')) {
@@ -134,6 +132,9 @@ function bundleJs(config) {
for (let lib of external) {
b.require(lib);
}
+ if (config.transpile) {
+ b.add(require.resolve('babel-polyfill'));
+ }
writeJsBundle(
b, './public/vendor.min.js', 'Bundled vendor JS', true);
}
@@ -142,7 +143,7 @@ function bundleJs(config) {
let outputFile = fs.createWriteStream('./public/app.min.js');
let b = browserify({debug: config.debug});
if (config.transpile) {
- b = b.transform(babelify);
+ b = b.transform('babelify');
}
writeJsBundle(
b.external(external).add(files),
diff --git a/client/js/controllers/users_controller.js b/client/js/controllers/users_controller.js
index 33c8620..53f485e 100644
--- a/client/js/controllers/users_controller.js
+++ b/client/js/controllers/users_controller.js
@@ -14,15 +14,15 @@ const UsersHeaderView = require('../views/users_header_view.js');
const UsersPageView = require('../views/users_page_view.js');
const EmptyView = require('../views/empty_view.js');
-const rankNames = {
- anonymous: 'Anonymous',
- restricted: 'Restricted user',
- regular: 'Regular user',
- power: 'Power user',
- moderator: 'Moderator',
- administrator: 'Administrator',
- nobody: 'Nobody',
-};
+const rankNames = new Map([
+ ['anonymous', 'Anonymous'],
+ ['restricted', 'Restricted user'],
+ ['regular', 'Regular user'],
+ ['power', 'Power user'],
+ ['moderator', 'Moderator'],
+ ['administrator', 'Administrator'],
+ ['nobody', 'Nobody'],
+]);
class UsersController {
constructor() {
@@ -96,7 +96,7 @@ class UsersController {
next();
} else {
api.get('/user/' + ctx.params.name).then(response => {
- response.user.rankName = rankNames[response.user.rank];
+ response.user.rankName = rankNames.get(response.user.rank);
ctx.state.user = response.user;
ctx.save();
this._cachedUser = response.user;
@@ -228,7 +228,7 @@ class UsersController {
if (rankIdx > myRankIdx) {
continue;
}
- ranks[rankIdentifier] = Object.values(rankNames)[rankIdx];
+ ranks[rankIdentifier] = rankNames.values()[rankIdx];
}
if (isLoggedIn) {
diff --git a/client/js/util/polyfill.js b/client/js/util/polyfill.js
index 2379e65..f11d13c 100644
--- a/client/js/util/polyfill.js
+++ b/client/js/util/polyfill.js
@@ -1,32 +1,5 @@
'use strict';
-require('babel-polyfill');
-
-const keys = Reflect.ownKeys;
-const reduce = Function.bind.call(Function.call, Array.prototype.reduce);
-const concat = Function.bind.call(Function.call, Array.prototype.concat);
-const isEnumerable = Function.bind.call(
- Function.call, Object.prototype.propertyIsEnumerable);
-
-if (!Object.values) {
- Object.values = function values(O) {
- return reduce(keys(O), (v, k) => concat(
- v, typeof k === 'string' && isEnumerable(O, k) ?
- [O[k]] :
- []), []);
- };
-}
-
-if (!Object.entries) {
- Object.entries = function entries(O) {
- return reduce(
- keys(O), (e, k) =>
- concat(e, typeof k === 'string' && isEnumerable(O, k) ?
- [[k, O[k]]] :
- []), []);
- };
-}
-
// fix iterating over NodeList in Chrome and Opera
NodeList.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
@@ -39,6 +12,7 @@ Node.prototype.prependChild = function(child) {
}
};
+// non standard
Promise.prototype.always = function(onResolveOrReject) {
return this.then(
onResolveOrReject,
@@ -48,6 +22,7 @@ Promise.prototype.always = function(onResolveOrReject) {
});
};
+// non standard
if (!String.prototype.format) {
String.prototype.format = function() {
let str = this.toString();
@@ -66,6 +41,7 @@ if (!String.prototype.format) {
};
}
+// non standard
Number.prototype.between = function(a, b, inclusive) {
const min = Math.min(a, b);
const max = Math.max(a, b);