Skip to content

Commit

Permalink
chore: [wip] additional es6 code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill-Hatalski committed Oct 15, 2024
1 parent d536bd9 commit 463c3ce
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 43 deletions.
8 changes: 4 additions & 4 deletions src/core/asyncProcess.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function asyncProcessFactory() {
* Tells if a process is running
* @returns {Boolean}
*/
isRunning: function isRunning() {
isRunning() {
return running;
},

Expand All @@ -50,7 +50,7 @@ function asyncProcessFactory() {
* @param {Function} [cb] - The process to start
* @returns {boolean} - Returns true if the process can be started
*/
start: function start(cb) {
start(cb) {
let started = false;
if (!running) {
steps = [];
Expand All @@ -74,7 +74,7 @@ function asyncProcessFactory() {
* @param {Promise} step
* @returns {asyncProcess}
*/
addStep: function addStep(step) {
addStep(step) {
steps.push(step);

/**
Expand All @@ -92,7 +92,7 @@ function asyncProcessFactory() {
* @param {Function} [cb] - A nodeback like function which will be called when all the deferred steps have finished or an error occurs
* @returns {Promise} - Returns the finish promise
*/
done: function done(cb) {
done(cb) {
const self = this;
const finish = Promise.all(steps);

Expand Down
12 changes: 6 additions & 6 deletions src/core/connectivity.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ import eventifier from './eventifier.js';
/**
* @type {Boolean} the current status, true means online
*/
var status = navigator.onLine;
let status = navigator.onLine;

/**
* The connectivity module
* @typedef {connectivity}
*/
var connectivity = eventifier({
const connectivity = eventifier({
/**
* Set manually as online
* @returns {connectivity} chains
* @fires {connectivity#online}
* @fires {connectivity#change}
*/
setOnline: function setOnline() {
setOnline() {
if (this.isOffline()) {
status = true;

Expand All @@ -55,7 +55,7 @@ var connectivity = eventifier({
* @fires {connectivity#offline}
* @fires {connectivity#change}
*/
setOffline: function setOffline() {
setOffline() {
if (this.isOnline()) {
status = false;

Expand All @@ -68,15 +68,15 @@ var connectivity = eventifier({
* Are we online ?
* @returns {Boolean}
*/
isOnline: function isOnline() {
isOnline() {
return status;
},

/**
* Are we offline
* @returns {Boolean}
*/
isOffline: function isOffline() {
isOffline() {
return !status;
}
});
Expand Down
18 changes: 9 additions & 9 deletions src/core/databinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import Filters from './filter/filters.js';
* @param {string} path - the property path
* @returns {*}
*/
const locate = function locate(obj, path) {
function locate(obj, path) {
const nodes = path.split('.');
const size = nodes.length;
let i = 1;
Expand All @@ -60,7 +60,7 @@ const locate = function locate(obj, path) {
* @param {string} path - the property path
* @param {string|boolean|number} value - the value to assign
*/
const update = function update(obj, path, value) {
function update(obj, path, value) {
const nodes = path.split('.');
const size = nodes.length;
let i;
Expand All @@ -86,7 +86,7 @@ const update = function update(obj, path, value) {
* @param {Object} obj - the object to locate property into
* @param {string} path - the property path
*/
const remove = function remove(obj, path) {
function remove(obj, path) {
const nodes = path.split('.');
const size = nodes.length;
let i;
Expand All @@ -112,7 +112,7 @@ const remove = function remove(obj, path) {
* @param {jQueryElement} $node - the element that contains the items
* @param {Boolean} [retry=false] - if we are in fault tolerancy context, to prevent deep recursivity
*/
const order = function order(obj, path, $node, retry) {
function order(obj, path, $node, retry) {
const values = locate(obj, path);
let changed = false;
if (_.isArray(values)) {
Expand Down Expand Up @@ -148,7 +148,7 @@ const order = function order(obj, path, $node, retry) {
* @param {string} path - the property path
* @param {jQueryElement} $node - the element that contains the items
*/
const resyncIndexes = function resyncIndexes(obj, path, $node) {
function resyncIndexes(obj, path, $node) {
const values = locate(obj, path);
if (_.isArray(values)) {
_.forEach(values, function (value, position) {
Expand All @@ -172,7 +172,7 @@ const resyncIndexes = function resyncIndexes(obj, path, $node) {
* @param {jQueryElement} $container
* @returns {jQueryElement}
*/
const toBind = function toBind($node, $container) {
function toBind($node, $container) {
if ($node[0].type && $node[0].name) {
if ($node[0].type === 'radio' || $node[0].type === 'checkbox') {
return $(`[name='${$node[0].name}']`, $container);
Expand All @@ -188,7 +188,7 @@ const toBind = function toBind($node, $container) {
* @param {String} eventName - the name of the event to bind
* @private
*/
const _unbind = function _unbind($node, $container, eventName) {
function _unbind($node, $container, eventName) {
if ($node.length > 0) {
const bounds = $._data($node[0], 'events');
if (
Expand All @@ -209,7 +209,7 @@ const _unbind = function _unbind($node, $container, eventName) {
* @param {String} eventName - the name of the event to bind
* @param {Function} cb - a jQuery event handler
*/
const _bindOnce = function _bindOnce($node, $container, eventName, cb) {
function _bindOnce($node, $container, eventName, cb) {
_unbind($node, $container, eventName);
if ($node.length > 0) {
const bounds = $._data($node[0], 'events');
Expand All @@ -236,7 +236,7 @@ const _bindOnce = function _bindOnce($node, $container, eventName, cb) {
* @param {Object} model
* @param {Object} options - to be documented
*/
const DataBinder = function DataBinder($container, model, options) {
function DataBinder($container, model, options) {
const self = this;
this.$container = $container;
this.model = model || {};
Expand Down
4 changes: 2 additions & 2 deletions src/core/polling.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function pollingFactory(config, pollingInterval = _defaultInterval) {
/**
* Gets the current action into asynchronous mode.
* The next iteration won't be executed until the resolve method has been called.
* However if the reject method is called, the polling is then stopped!
* However, if the reject method is called, the polling is then stopped!
* @returns {Object} Returns a promise resolver that provides resolve() and reject() methods
*/
async() {
Expand Down Expand Up @@ -223,7 +223,7 @@ function pollingFactory(config, pollingInterval = _defaultInterval) {
return this;
}

// the next() method can be called either to force a next iteration or to start immediately the action
// the next() method can be called either to force a next iteration or to start immediately the action,
// so we need to ensure the schedule is not blocked
state.stopped = false;

Expand Down
18 changes: 9 additions & 9 deletions src/core/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function timerFactory(config) {
* @param {Number} [startDuration] - Initial duration (default: 0)
* @returns {timer}
*/
start: function start(startDuration) {
start(startDuration) {
begin = now();
last = begin;
duration = startDuration || 0;
Expand All @@ -58,7 +58,7 @@ function timerFactory(config) {
* Gets the time elapsed since the last tick
* @returns {number}
*/
tick: function tick() {
tick() {
var timestamp = now();
var elapsed;
if (state.running) {
Expand All @@ -72,7 +72,7 @@ function timerFactory(config) {
* Pause the timer
* @returns {timer}
*/
pause: function pause() {
pause() {
if (state.running) {
duration += now() - begin;
state.running = false;
Expand All @@ -85,7 +85,7 @@ function timerFactory(config) {
* Resume the timer
* @returns {timer}
*/
resume: function resume() {
resume() {
if (!state.running) {
begin = now();
last = begin;
Expand All @@ -100,7 +100,7 @@ function timerFactory(config) {
* Stops the timer
* @returns {timer}
*/
stop: function stop() {
stop() {
if (state.running) {
duration += now() - begin;
}
Expand All @@ -116,7 +116,7 @@ function timerFactory(config) {
* If the timer is stopped, gets the total duration between start and stop.
* @returns {number}
*/
getDuration: function getDuration() {
getDuration() {
if (state.running) {
return duration + (now() - begin);
}
Expand All @@ -128,7 +128,7 @@ function timerFactory(config) {
* @param {String} stateName
* @returns {Boolean}
*/
is: function is(stateName) {
is(stateName) {
return !!state[stateName];
},

Expand All @@ -137,7 +137,7 @@ function timerFactory(config) {
* @param {Number} time
* @returns {timer}
*/
add: function add(time) {
add(time) {
time = parseFloat(time);
duration += time;
last -= time;
Expand All @@ -149,7 +149,7 @@ function timerFactory(config) {
* @param {Number} time
* @returns {timer}
*/
sub: function sub(time) {
sub(time) {
time = parseFloat(time);
duration -= time;
last += time;
Expand Down
3 changes: 2 additions & 1 deletion src/core/tokenHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import _ from 'lodash';
import module from 'module';
import tokenStoreFactory from './tokenStore.js';
import promiseQueue from './promiseQueue.js';
import store from "./store.js";

let validateTokensOpt = true;
let clientConfigFetched = false;
Expand Down Expand Up @@ -85,7 +86,7 @@ export default function tokenHandlerFactory(options) {
// Some async checks before we go for the token:
return tokenStore
.expireOldTokens()
.then(() => {
.then(async () => {
if (!clientConfigFetched) {
// Client Config allowed! (first and only time)
return this.getClientConfigTokens()
Expand Down
2 changes: 1 addition & 1 deletion src/util/capitalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import _ from 'lodash';
* @param {Boolean} allWords capitalize all words, similar to PHP's ucWords()
* @returns {*}
*/
const capitalize = function capitalize(input, allWords) {
function capitalize(input, allWords) {
const ucFirst = function ucFirst(str) {
return str.charAt(0).toUpperCase() + str.substr(1);
};
Expand Down
8 changes: 4 additions & 4 deletions src/util/httpErrorParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ export default {
* @param {String} errorThrown - textual portion of the HTTP status, such as "Not Found" or "Internal Server Error."
* @returns {Error} the new error
*/
parse: function parse(xhr, options, errorThrown) {
var msg;
var json;
var error;
parse(xhr, options, errorThrown) {
let msg;
let json;
let error;
try {
json = JSON.parse(xhr.responseText);
msg = json.message ? json.message : errorThrown;
Expand Down
8 changes: 4 additions & 4 deletions src/util/namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const namespaceHelper = {
* @param {Boolean} [normalize] - lower case the string to normalize all the names
* @returns {String[]} the list of names (no empty, no duplicate)
*/
split: function split(names, normalize) {
split(names, normalize) {
if (!_.isString(names) || _.isEmpty(names)) {
return [];
}
Expand All @@ -67,7 +67,7 @@ const namespaceHelper = {
* @param {String} namespaced - the namespaced name
* @returns {String} the name part
*/
getName: function getName(namespaced) {
getName(namespaced) {
if (!_.isString(namespaced) || _.isEmpty(namespaced)) {
return '';
}
Expand All @@ -83,7 +83,7 @@ const namespaceHelper = {
* @param {String} [defaultNs] - the default namespace
* @returns {String} the namespace, that defaults to defaultNs
*/
getNamespace: function getNamespace(namespaced, defaultNs) {
getNamespace(namespaced, defaultNs) {
if (!_.isString(namespaced) || _.isEmpty(namespaced)) {
return '';
}
Expand All @@ -100,7 +100,7 @@ const namespaceHelper = {
* @param {Boolean} [normalize] - lower case the string to normalize all the names
* @returns {String} - The list of namespaced names
*/
namespaceAll: function namespaceAll(names, namespace, normalize) {
namespaceAll(names, namespace, normalize) {
let suffix;
if (!_.isArray(names)) {
names = namespaceHelper.split(names, normalize);
Expand Down
4 changes: 2 additions & 2 deletions src/util/position.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default {
* @param {HTMLElement} element - the element to check against the container
* @returns {Boolean|undefined} or undefined if the parameters are incorrect, so check your return value type.
*/
isInside: function isInside(container, element) {
isInside(container, element) {
let containerCoords;
let elementCoords;
if (container instanceof HTMLElement && element instanceof HTMLElement) {
Expand Down Expand Up @@ -66,7 +66,7 @@ export default {
* @param {HTMLElement} element - the element to check against the container
* @returns {Boolean|undefined} or undefined if the parameters are incorrect, so check your return value type.
*/
isOver: function isInside(container, element) {
isOver(container, element) {
let containerCoords;
let elementCoords;
if (container instanceof HTMLElement && element instanceof HTMLElement) {
Expand Down
2 changes: 1 addition & 1 deletion src/util/typeCaster.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default {
* @param {Boolean} defaultValue
* @returns {Boolean} true if value === "true", defaultValue if set, false if defaultValue not set
*/
strToBool: function strToBool(value, defaultValue) {
strToBool(value, defaultValue) {
if (_.isBoolean(value)) {
return value;
} else if (_.isString(value)) {
Expand Down

0 comments on commit 463c3ce

Please sign in to comment.