Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES6: migrated "util" #1114

Merged
merged 49 commits into from
Apr 25, 2017
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
f5fa8c2
worker
bennycode Apr 21, 2017
518df38
[ci skip]
bennycode Apr 21, 2017
e0fbb2e
wording
bennycode Apr 21, 2017
289acda
[ci skip]
bennycode Apr 21, 2017
49684cd
[ci skip]
bennycode Apr 21, 2017
f9c7ab8
[ci skip]
bennycode Apr 21, 2017
a974bca
[ci skip]
bennycode Apr 21, 2017
b533fad
confirm
bennycode Apr 21, 2017
a605cf7
[ci skip]
bennycode Apr 21, 2017
f89513a
[ci skip]
bennycode Apr 21, 2017
a5e1ab7
es6
bennycode Apr 21, 2017
f2fef67
DebugUtil
bennycode Apr 21, 2017
f12cef4
Linting
bennycode Apr 21, 2017
dee0d7e
z.util.KEYCODE
bennycode Apr 21, 2017
c8ad04c
KeyUtil
bennycode Apr 22, 2017
6079fe7
LocalizerUtil
bennycode Apr 22, 2017
ea6e8af
marked
bennycode Apr 22, 2017
96766a5
moment
bennycode Apr 22, 2017
32b1554
NumberUtil
bennycode Apr 22, 2017
7ee62c3
tests pass
bennycode Apr 22, 2017
519b8b2
protobuf
bennycode Apr 22, 2017
5a19a52
scroll-helpers
bennycode Apr 22, 2017
ce40405
Statistics
bennycode Apr 22, 2017
6aa721f
Statistics
bennycode Apr 22, 2017
89a37e6
StorageUtil
bennycode Apr 22, 2017
205cb5b
StringUtil
bennycode Apr 22, 2017
eb12f4b
No Array.from
bennycode Apr 22, 2017
6614a5f
util
bennycode Apr 22, 2017
9466e7f
tests pass
bennycode Apr 22, 2017
3f883aa
JSDoc declaration for optional
bennycode Apr 22, 2017
8d6d0ec
Login fix
bennycode Apr 22, 2017
b440c39
Merge branch 'dev' into es6/util
bennycode Apr 24, 2017
f52d0ce
[ci skip]
bennycode Apr 24, 2017
18ca135
[ci skip]
bennycode Apr 24, 2017
1836115
[ci skip]
bennycode Apr 24, 2017
3f1fe58
[ci skip]
bennycode Apr 24, 2017
78026f8
[ci skip]
bennycode Apr 24, 2017
28edc65
[ci skip]
bennycode Apr 24, 2017
0085ca8
[ci skip]
bennycode Apr 24, 2017
b969b3a
[ci skip]
bennycode Apr 24, 2017
81031a1
[ci skip]
bennycode Apr 24, 2017
2504a22
[ci skip]
bennycode Apr 24, 2017
16c99d2
[ci skip]
bennycode Apr 24, 2017
27a8f4b
[ci skip]
bennycode Apr 24, 2017
16bc8d3
[ci skip]
bennycode Apr 24, 2017
e03b7f1
[ci skip]
bennycode Apr 24, 2017
b42458d
[ci skip]
bennycode Apr 24, 2017
8adf5ec
fixed indices
bennycode Apr 24, 2017
4937ef6
Added filter check
bennycode Apr 25, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,25 @@ extends:
"eslint:recommended"

globals:
_: true
$: true
_: true
amplify: true
cryptobox: true
CryptoJS: true
dcodeIO: true
hljs: true,
ko: true
libsodium: true
LRUCache: true
marked: true,
moment: true
pako: true
platform: true
Proteus: true
Raygun: true
sodium: true
twttr: true
UUID: true
wire: true
z: true

Expand Down
5 changes: 1 addition & 4 deletions app/script/entity/message/MemberMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ z.entity.MemberMessage = class MemberMessage extends z.entity.SystemMessage {
.map((user_et) => user_et);
});

this._generate_name_string = (declension) => {
if (declension === null) {
declension = z.string.Declension.ACCUSATIVE;
}
this._generate_name_string = (declension = z.string.Declension.ACCUSATIVE) => {
return z.util.LocalizerUtil.join_names(this.joined_user_ets(), declension);
};

Expand Down
2 changes: 1 addition & 1 deletion app/script/main/app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class z.main.App
if is_reload and error.type not in [z.client.ClientError.TYPE.MISSING_ON_BACKEND, z.client.ClientError.TYPE.NO_LOCAL_CLIENT]
@auth.client.execute_on_connectivity(z.service.Client::CONNECTIVITY_CHECK_TRIGGER.APP_INIT_RELOAD).then -> window.location.reload false
else if navigator.onLine
@logger.error "Caused by: #{error?.message or error}"
@logger.error "Caused by: #{error?.message or error}", error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problematic. If error is a string as it sometimes is and not the error object, we will end up with a log message that does no longer contain the "Caused by reference". Maybe we should be more explicit and do a proper _.isObject check with tow error logging cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, this is due to our logger implementation, right?

Raygun.send error if error instanceof z.storage.StorageError
@logout 'init_app'
else
Expand Down
100 changes: 0 additions & 100 deletions app/script/util/ArrayUtil.coffee

This file was deleted.

128 changes: 128 additions & 0 deletions app/script/util/ArrayUtil.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* Wire
* Copyright (C) 2017 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
*/

'use strict';

window.z = window.z || {};
window.z.util = z.util || {};

z.util.ArrayUtil = {
chunk(array, size) {
const chunks = [];
const temp_array = Array.from(array);
while (temp_array.length) {
chunks.push(temp_array.splice(0, size));
}
return chunks;
},
find_closest(array, value) {
let closest = array[0];

array.forEach(function(current) {
if (value >= current) {
closest = current;
}
});

return closest;
},
get_next_item(array, item, filter) {
const index = array.indexOf(item);
const next_index = index + 1;

// couldn't find the item
if (index === -1) {
return null;
}

// item is last item in the array
if ((next_index === array.length) && (index > 0)) {
return array[index - 1];
}

if (next_index >= array.length) {
return undefined;
}

for (let i = next_index; i <= array.length; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have a proper array. We can use that:

for (const item of array) {
  if(!_.isFunction(filter) || !!filter(item)) {
    return item
  }
}

const current_item = array[i];
if ((filter == null) || !!filter(current_item)) {
return current_item;
}
}
},
/**
* Interpolates an array of numbers using linear interpolation
*
* @param {Array<any>} array - source
* @param {number} length - new length
* @returns {Array<any>} new array with interpolated values
*/
interpolate(array, length) {
const new_array = [];
const scale_factor = (array.length - 1) / (length - 1);

new_array[0] = array[0];
new_array[length - 1] = array[array.length - 1];

for (let i = 1; i < length - 1; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (const index of [0..length - 1])

const original_index = i * scale_factor;
const before = Math.floor(original_index).toFixed();
const after = Math.ceil(original_index).toFixed();
const point = original_index - before;
new_array[i] = array[before] + ((array[after] - array[before]) * point); // linear interpolation
}

return new_array;
},
is_last_item(array, item) {
return array.indexOf(item) === (array.length - 1);
},
iterate_index(array, current_index) {
if (!_.isArray(array) || !_.isNumber(current_index)) {
return undefined;
}

if (!array.length) {
return undefined;
}

return (current_index + 1) % array.length;
},
/**
* Returns random element
* @param {Array} array - source
* @returns {Object} random element
*/
random_element(array = []) {
return array[Math.floor(Math.random() * array.length)];
},
/**
* Remove given element from array
* @param {Array} array - source
* @param {Object} element - Element which should be removed
* @returns {Array|undefined} containing the removed element
*/
remove_element(array = [], element) {
const index = array.indexOf(element);
if (index > -1) {
return array.splice(index, 1);
}
},
};
Loading