Commit c7319281 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(Utils): sort functions declarations

parent ba804f5d
...@@ -35,6 +35,9 @@ Item { ...@@ -35,6 +35,9 @@ Item {
} }
_mouseArea.parent = parent _mouseArea.parent = parent
// Must be true if a fake parent is used and if `mouseArea`
// is not in the same window that `item`.
_mouseAlwaysOutside = _mouseAlwaysOutside =
_mouseArea.parent !== Utils.getTopParent(item) _mouseArea.parent !== Utils.getTopParent(item)
} }
...@@ -74,7 +77,10 @@ Item { ...@@ -74,7 +77,10 @@ Item {
positionEvent.accepted = false positionEvent.accepted = false
// Click is outside or not. // Click is outside or not.
if (_mouseAlwaysOutside || !Utils.pointIsInItem(this, item, positionEvent)) { if (
_mouseAlwaysOutside ||
!Utils.pointIsInItem(this, item, positionEvent)
) {
if (_timeout != null) { if (_timeout != null) {
// Remove existing timeout to avoid the creation of // Remove existing timeout to avoid the creation of
// many children. // many children.
......
...@@ -212,13 +212,28 @@ function _computeOptimizedCb (func, context) { ...@@ -212,13 +212,28 @@ function _computeOptimizedCb (func, context) {
}) : func }) : func
} }
// ------------------------------------------------------------------- function _indexFinder (array, cb, context) {
var length = array.length
// Convert a snake_case string to a lowerCamelCase string. for (var i = 0; i < length; i++) {
function snakeToCamel (s) { if (cb(array[index], index, array)) {
return s.replace(/(\_\w)/g, function (matches) { return i
return matches[1].toUpperCase() }
}) }
return -1
}
function _keyFinder (obj, cb, context) {
var keys = Object.keys(obj)
var length = keys.length
for (var i = 0; i < length; i++) {
var key = keys[i]
if (cb(obj[key], key, obj)) {
return key
}
}
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
...@@ -232,49 +247,34 @@ function assert (condition, message) { ...@@ -232,49 +247,34 @@ function assert (condition, message) {
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Returns the extension of a filename. // Returns an array from a `object` or `array` argument.
function getExtension (str) { function ensureArray (obj) {
var index = str.lastIndexOf('.') if (isArray(obj)) {
return obj
if (index === -1) {
return ''
} }
return str.slice(index + 1) var keys = Object.keys(obj)
} var length = keys.length
var values = Array(length)
// -------------------------------------------------------------------
// Test if a string starts by a given string.
function startsWith (str, searchStr) {
return str.slice(0, searchStr.length) === searchStr
}
// -------------------------------------------------------------------
// Invoke a `cb` function with each value of the interval: `[0, n[`.
// Return a mapped array created with the returned values of `cb`.
function times (n, cb, context) {
var arr = Array(Math.max(0, n))
cb = _computeOptimizedCb(cb, context, 1)
for (var i = 0; i < n; i++) { for (var i = 0; i < length; i++) {
arr[i] = cb(i) values[i] = obj[keys[i]]
} }
return arr return values
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
function isArray (array) { // Get the first matching value in a array or object.
return (array instanceof Array) // The matching value is obtained if `cb` returns true.
} function find (obj, cb, context) {
cb = _computeOptimizedCb(cb, context)
// ------------------------------------------------------------------- var finder = isArray(obj) ? _indexFinder : _keyFinder
var key = finder(obj, cb, context)
function isString (string) { return key != null && key !== -1 ? obj[key] : null
return typeof string === 'string' || string instanceof String
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
...@@ -319,21 +319,15 @@ function genRandomNumberBetweenIntervals (intervals) { ...@@ -319,21 +319,15 @@ function genRandomNumberBetweenIntervals (intervals) {
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Returns an array from a `object` or `array` argument. // Returns the extension of a filename.
function ensureArray (obj) { function getExtension (str) {
if (isArray(obj)) { var index = str.lastIndexOf('.')
return obj
}
var keys = Object.keys(obj)
var length = keys.length
var values = Array(length)
for (var i = 0; i < length; i++) { if (index === -1) {
values[i] = obj[keys[i]] return ''
} }
return values return str.slice(index + 1)
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
...@@ -359,37 +353,43 @@ function includes (obj, value, startIndex) { ...@@ -359,37 +353,43 @@ function includes (obj, value, startIndex) {
// ------------------------------------------------------------------- // -------------------------------------------------------------------
function _indexFinder (array, cb, context) { function isArray (array) {
var length = array.length return (array instanceof Array)
}
for (var i = 0; i < length; i++) { // -------------------------------------------------------------------
if (cb(array[index], index, array)) {
return i
}
}
return -1 function isString (string) {
return typeof string === 'string' || string instanceof String
} }
function _keyFinder (obj, cb, context) { // -------------------------------------------------------------------
var keys = Object.keys(obj)
var length = keys.length
for (var i = 0; i < length; i++) { // Convert a snake_case string to a lowerCamelCase string.
var key = keys[i] function snakeToCamel (s) {
if (cb(obj[key], key, obj)) { return s.replace(/(\_\w)/g, function (matches) {
return key return matches[1].toUpperCase()
} })
}
} }
// Get the first matching value in a array or object. // -------------------------------------------------------------------
// The matching value is obtained if `cb` returns true.
function find (obj, cb, context) {
cb = _computeOptimizedCb(cb, context)
var finder = isArray(obj) ? _indexFinder : _keyFinder // Test if a string starts by a given string.
var key = finder(obj, cb, context) function startsWith (str, searchStr) {
return str.slice(0, searchStr.length) === searchStr
}
return key != null && key !== -1 ? obj[key] : null // -------------------------------------------------------------------
// Invoke a `cb` function with each value of the interval: `[0, n[`.
// Return a mapped array created with the returned values of `cb`.
function times (n, cb, context) {
var arr = Array(Math.max(0, n))
cb = _computeOptimizedCb(cb, context, 1)
for (var i = 0; i < n; i++) {
arr[i] = cb(i)
}
return arr
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment