summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxime Quandalle <maxime@quandalle.com>2015-10-22 04:02:12 +0200
committerMaxime Quandalle <maxime@quandalle.com>2015-10-22 18:13:12 +0200
commitaa974aa54ab6e5b7db7450206d12b44ffb3a0306 (patch)
treeb501ee16fa630e19b95d99ffc3984e30301e096a
parentc6b12dc5ada1b37d759796fefe0dbc5b327f130c (diff)
downloadwekan-aa974aa54ab6e5b7db7450206d12b44ffb3a0306.tar.gz
wekan-aa974aa54ab6e5b7db7450206d12b44ffb3a0306.tar.bz2
wekan-aa974aa54ab6e5b7db7450206d12b44ffb3a0306.zip
Prefer ES5 methods over underscore utilities
Since 07cc454 (ie the switch to Meteor 1.2) we includes the `es5-shim` polyfill to support methods like `Array.prototype.forEach` in a consistent way across all supported browsers (IE8+). MDG recently released a blog post recommending the use of these native methods instead of underscore [0]. We know follow this recommendation. This commit also favor some ES6 features (argument defaults, destructing assignment) in places where we didn’t use them. [0]: http://info.meteor.com/blog/es2015-get-started
-rw-r--r--client/components/cards/cardDetails.js5
-rw-r--r--client/components/cards/labels.js2
-rw-r--r--client/components/main/editor.js2
-rw-r--r--client/components/sidebar/sidebar.js4
-rw-r--r--client/components/users/userHeader.js2
-rw-r--r--client/config/accounts.js2
-rw-r--r--client/lib/filter.js4
-rw-r--r--client/lib/modal.js4
-rw-r--r--client/lib/multiSelection.js9
-rw-r--r--client/lib/popup.js4
-rw-r--r--models/boards.js2
-rw-r--r--models/users.js16
-rw-r--r--server/migrations.js6
-rw-r--r--server/publications/boards.js2
14 files changed, 33 insertions, 31 deletions
diff --git a/client/components/cards/cardDetails.js b/client/components/cards/cardDetails.js
index 5e07abab..2d2679ec 100644
--- a/client/components/cards/cardDetails.js
+++ b/client/components/cards/cardDetails.js
@@ -62,7 +62,8 @@ BlazeComponent.extendComponent({
},
};
- return [_.extend(events, {
+ return [{
+ ...events,
'click .js-close-card-details'() {
Utils.goBoardId(this.data().boardId);
},
@@ -86,7 +87,7 @@ BlazeComponent.extendComponent({
this.parentComponent().showOverlay.set(true);
this.parentComponent().mouseHasEnterCardDetails = true;
},
- })];
+ }];
},
}).register('cardDetails');
diff --git a/client/components/cards/labels.js b/client/components/cards/labels.js
index 6a411561..4e61a0c6 100644
--- a/client/components/cards/labels.js
+++ b/client/components/cards/labels.js
@@ -13,7 +13,7 @@ BlazeComponent.extendComponent({
},
labels() {
- return _.map(labelColors, (color) => {
+ return labelColors.map((color) => {
return { color, name: '' };
});
},
diff --git a/client/components/main/editor.js b/client/components/main/editor.js
index 67b65bec..168c85d0 100644
--- a/client/components/main/editor.js
+++ b/client/components/main/editor.js
@@ -54,7 +54,7 @@ const at = HTML.CharRef({html: '&commat;', str: '@'});
Blaze.Template.registerHelper('mentions', new Template('mentions', function() {
const view = this;
const currentBoard = Boards.findOne(Session.get('currentBoard'));
- const knowedUsers = _.map(currentBoard.members, (member) => {
+ const knowedUsers = currentBoard.members.map((member) => {
member.username = Users.findOne(member.userId).username;
return member;
});
diff --git a/client/components/sidebar/sidebar.js b/client/components/sidebar/sidebar.js
index 72866055..ccb9f2f5 100644
--- a/client/components/sidebar/sidebar.js
+++ b/client/components/sidebar/sidebar.js
@@ -95,10 +95,10 @@ BlazeComponent.extendComponent({
events() {
// XXX Hacky, we need some kind of `super`
const mixinEvents = this.getMixin(Mixins.InfiniteScrolling).events();
- return mixinEvents.concat([{
+ return [...mixinEvents, {
'click .js-toggle-sidebar': this.toggle,
'click .js-back-home': this.setView,
- }]);
+ }];
},
}).register('sidebar');
diff --git a/client/components/users/userHeader.js b/client/components/users/userHeader.js
index 0f91fd15..a7382769 100644
--- a/client/components/users/userHeader.js
+++ b/client/components/users/userHeader.js
@@ -41,7 +41,7 @@ Template.changePasswordPopup.onRendered(function() {
Template.changeLanguagePopup.helpers({
languages() {
- return _.map(TAPi18n.getLanguages(), (lang, tag) => {
+ return TAPi18n.getLanguages().map((lang, tag) => {
const name = lang.name;
return { tag, name };
});
diff --git a/client/config/accounts.js b/client/config/accounts.js
index df0935f7..d475e6b2 100644
--- a/client/config/accounts.js
+++ b/client/config/accounts.js
@@ -25,7 +25,7 @@ AccountsTemplates.configure({
},
});
-_.each(['signIn', 'signUp', 'resetPwd', 'forgotPwd', 'enrollAccount'],
+['signIn', 'signUp', 'resetPwd', 'forgotPwd', 'enrollAccount'].forEach(
(routeName) => AccountsTemplates.configureRoute(routeName));
// We display the form to change the password in a popup window that already
diff --git a/client/lib/filter.js b/client/lib/filter.js
index f7baf480..74305284 100644
--- a/client/lib/filter.js
+++ b/client/lib/filter.js
@@ -95,7 +95,7 @@ Filter = {
return {};
const filterSelector = {};
- _.forEach(this._fields, (fieldName) => {
+ this._fields.forEach((fieldName) => {
const filter = this[fieldName];
if (filter._isActive())
filterSelector[fieldName] = filter._getMongoSelector();
@@ -116,7 +116,7 @@ Filter = {
},
reset() {
- _.forEach(this._fields, (fieldName) => {
+ this._fields.forEach((fieldName) => {
const filter = this[fieldName];
filter.reset();
});
diff --git a/client/lib/modal.js b/client/lib/modal.js
index 5b3392b2..7b7516e0 100644
--- a/client/lib/modal.js
+++ b/client/lib/modal.js
@@ -21,9 +21,9 @@ window.Modal = new class {
}
}
- open(modalName, options) {
+ open(modalName, { onCloseGoTo = ''}) {
this._currentModal.set(modalName);
- this._onCloseGoTo = options && options.onCloseGoTo || '';
+ this._onCloseGoTo = onCloseGoTo;
}
};
diff --git a/client/lib/multiSelection.js b/client/lib/multiSelection.js
index c2bb2bbc..eeb2015d 100644
--- a/client/lib/multiSelection.js
+++ b/client/lib/multiSelection.js
@@ -119,12 +119,13 @@ MultiSelection = {
}
},
- toggle(cardIds, options) {
+ toggle(cardIds, options = {}) {
cardIds = _.isString(cardIds) ? [cardIds] : cardIds;
- options = _.extend({
+ options = {
add: true,
remove: true,
- }, options || {});
+ ...options,
+ };
if (!this.isActive()) {
this.reset();
@@ -133,7 +134,7 @@ MultiSelection = {
const selectedCards = this._selectedCards.get();
- _.each(cardIds, (cardId) => {
+ cardIds.forEach((cardId) => {
const indexOfCard = selectedCards.indexOf(cardId);
if (options.remove && indexOfCard > -1)
diff --git a/client/lib/popup.js b/client/lib/popup.js
index 3c39af29..7418d938 100644
--- a/client/lib/popup.js
+++ b/client/lib/popup.js
@@ -91,7 +91,7 @@ window.Popup = new class {
if (!self.isOpen()) {
self.current = Blaze.renderWithData(self.template, () => {
self._dep.depend();
- return _.extend(self._getTopStack(), { stack: self._stack });
+ return { ...self._getTopStack(), stack: self._stack };
}, document.body);
} else {
@@ -191,7 +191,7 @@ window.Popup = new class {
// We close a potential opened popup on any left click on the document, or go
// one step back by pressing escape.
const escapeActions = ['back', 'close'];
-_.each(escapeActions, (actionName) => {
+escapeActions.forEach((actionName) => {
EscapeActions.register(`popup-${actionName}`,
() => Popup[actionName](),
() => Popup.isOpen(),
diff --git a/models/boards.js b/models/boards.js
index 4d9fd7c0..1d365a95 100644
--- a/models/boards.js
+++ b/models/boards.js
@@ -279,7 +279,7 @@ Boards.before.insert((userId, doc) => {
// Handle labels
const colors = Boards.simpleSchema()._schema['labels.$.color'].allowedValues;
const defaultLabelsColors = _.clone(colors).splice(0, 6);
- doc.labels = _.map(defaultLabelsColors, (color) => {
+ doc.labels = defaultLabelsColors.map((color) => {
return {
color,
_id: Random.id(6),
diff --git a/models/users.js b/models/users.js
index 1ea09a03..b35104ec 100644
--- a/models/users.js
+++ b/models/users.js
@@ -14,13 +14,13 @@ Users.helpers({
},
starredBoards() {
- const starredBoardIds = this.profile.starredBoards || [];
- return Boards.find({archived: false, _id: {$in: starredBoardIds}});
+ const {starredBoards = []} = this.profile;
+ return Boards.find({archived: false, _id: {$in: starredBoards}});
},
hasStarred(boardId) {
- const starredBoardIds = this.profile.starredBoards || [];
- return _.contains(starredBoardIds, boardId);
+ const {starredBoards = []} = this.profile;
+ return _.contains(starredBoards, boardId);
},
isBoardMember() {
@@ -54,9 +54,9 @@ Users.helpers({
return profile.initials;
else if (profile.fullname) {
- return _.reduce(profile.fullname.split(/\s+/), (memo, word) => {
+ return profile.fullname.split(/\s+/).reduce((memo = '', word) => {
return memo + word[0];
- }, '').toUpperCase();
+ }).toUpperCase();
} else {
return this.username[0].toUpperCase();
@@ -130,7 +130,7 @@ if (Meteor.isServer) {
// b. We use it to find deleted and newly inserted ids by using it in one
// direction and then in the other.
function incrementBoards(boardsIds, inc) {
- _.forEach(boardsIds, (boardId) => {
+ boardsIds.forEach((boardId) => {
Boards.update(boardId, {$inc: {stars: inc}});
});
}
@@ -149,7 +149,7 @@ if (Meteor.isServer) {
// Insert the Welcome Board
Boards.insert(ExampleBoard, (err, boardId) => {
- _.forEach(['Basics', 'Advanced'], (title) => {
+ ['Basics', 'Advanced'].forEach((title) => {
const list = {
title,
boardId,
diff --git a/server/migrations.js b/server/migrations.js
index 509d8510..99125976 100644
--- a/server/migrations.js
+++ b/server/migrations.js
@@ -43,7 +43,7 @@ Migrations.add('board-background-color', () => {
});
Migrations.add('lowercase-board-permission', () => {
- _.forEach(['Public', 'Private'], (permission) => {
+ ['Public', 'Private'].forEach((permission) => {
Boards.update(
{ permission },
{ $set: { permission: permission.toLowerCase() } },
@@ -116,11 +116,11 @@ Migrations.add('add-member-isactive-field', () => {
const formerUsers = _.difference(allUsersWithSomeActivity, currentUsers);
const newMemberSet = [];
- _.forEach(board.members, (member) => {
+ board.members.forEach((member) => {
member.isActive = true;
newMemberSet.push(member);
});
- _.forEach(formerUsers, (userId) => {
+ formerUsers.forEach((userId) => {
newMemberSet.push({
userId,
isAdmin: false,
diff --git a/server/publications/boards.js b/server/publications/boards.js
index 403d0084..4ab7a12e 100644
--- a/server/publications/boards.js
+++ b/server/publications/boards.js
@@ -10,7 +10,7 @@ Meteor.publish('boards', function() {
// Defensive programming to verify that starredBoards has the expected
// format -- since the field is in the `profile` a user can modify it.
- const starredBoards = Users.findOne(this.userId).profile.starredBoards || [];
+ const {starredBoards = []} = Users.findOne(this.userId).profile;
check(starredBoards, [String]);
return Boards.find({