function(err, result, row) {
);function CheckLoginPromise(login){
return new Promise(
(resolve, reject) => DataBase.Handle.query('SELECT * FROM `users` WHERE `login` = ?', [login], function(err, result, row) {
if(err) return reject(err);
if(result.length > 0) {
console.log(result);
return resolve(true);
}
resolve(false);
})
)
}
CheckLoginPromise(login).then(bool => {
// делаем что-то
})
const bool = await CheckLoginPromise(login);
function loop(array, getPromise) {
array = array.slice();
const responses = [];
return new Promise(function innerLoop(resolve, reject) {
if (array.length) {
return getPromise(array.shift()).then(response => {
responses.push(response);
innerLoop(resolve, reject);
}, reject);
}
resolve(responses);
});
}
function request(url) {
return new Promise((res, rej) => {
const delayTime = Math.floor(Math.random() * 10000) + 1;
setTimeout(() => res(url), delayTime);
});
}
loop(['a', 'b'], request).then(console.log, console.error);
if (node.children[0].value == 'on' ) { inputRadioValue(node.children[0]); }
-->if (node.children[0].value == 'on' ) { return inputRadioValue(node.children[0]); }
return false
. const today = moment().startOf('day');
const dateFormat = 'YYYY-MM-DD HH:mm:ss';
const mapFunc = ({ End, Start, Amount }) => {
const points = [End, Start];
const shift = moment(today).seconds(Start);
const shifts = [];
const order = Start > End;
for (let i = 0; i < Amount; i++) {
shifts.push(
shift.format(dateFormat)
+ ' - '
+ shift
.hours(0) // очищаем часы
.minutes(0) // и минуты
.seconds(points[i % 2]) // чередуем временную точку: чёт - End, нечёт - Start
.add(i % 2 ^ order, 'd') // добавляем день если смена переходит на следующий
.format(dateFormat)
)
}
return shifts
}
console.log(mapFunc({
"Start": 25200,
"End": 68400,
"Amount": 5
}));
yarn serve
, а через yarn electron:serve. Как и билдить. Читайте описание тех модулей, что подключаете. function getDebouncedReq(params) {
var state = debounced.state = false;
var _debounce = null;
var _interval = null;
var _that = null, _args = [];
function debounced() {
_that = this;
_args = Array.prototype.slice.call(arguments, 0);
if(state === false) {
state = debounced.state = true;
if(params.onOnline)
params.onOnline.apply(_that, _args);
_interval = setInterval(function(){
if(params.onInterval)
params.onInterval.apply(_that, _args);
}, params.interval || 1000);
}
clearTimeout(_debounce);
_debounce = setTimeout(function(){
clearInterval(_interval)
state = debounced.state = false;
if(params.onOffline)
params.onOffline.apply(_that, _args);
}, params.idleWait || 60000);
}
return debounced;
}
$(document).ready( function(){
var requester = getDebouncedReq({
idleWait: 6000,
interval: 1000,
onOffline: function(){
console.log('offline');
},
onOnline: function(){
console.log('online');
},
onInterval: function(){
console.log('interval');
}
}, 10000)
$(document).bind('mousemove keydown scroll', requester);
$(document).trigger("mousemove");
$(document).bind('click', function() {
alert(requester.state)
});
});
svg
и навешать обработчики вручную.geojson
версию и использовать любую либу, умеющую с ним работать.typeof obj.field.text === 'undefined'
: typeof
даёт строку.if (obj.field?.text === undefined)
если obj
есть, и соответственно if (obj?.field?.text === undefined)
если неизвестно.if (!(typeof obj.field !== 'undefined' && typeof obj.field.text !== 'undefined' ))
Или использовать функцию-хэлпер, например if (get(obj, 'field.text') === undefined)
из lodash. children
даже если пустой:function unFlatten(array) {
const childrenMap = Object.create(null);
for(const item of array) {
if(item.parent in childrenMap)
childrenMap[item.parent].push(item);
else
childrenMap[item.parent] = [item];
if(!childrenMap[item.id]) childrenMap[item.id] = [];
item.children = childrenMap[item.id];
};
return childrenMap[null]
}
children
только там где нужны.function unFlatten(array) {
const childrenMap = Object.create(null);
const secondPass = [];
for(const item of array) {
if(item.parent in childrenMap)
childrenMap[item.parent].push(item);
else
childrenMap[item.parent] = [item];
if(item.id in childrenMap)
item.children = childrenMap[item.id];
else
secondPass.push(item)
};
for(const item of secondPass) {
if(item.id in childrenMap)
item.children = childrenMap[item.id];
};
return childrenMap[null]
}
function unFlatten(array) {
const map = Object.create(null);
const secondPass = [];
for(const item of array) {
map[item.id] = item;
if(item.parent in map) {
if('children' in map[item.parent])
map[item.parent].children.push(item)
else
map[item.parent].children = [item];
} else {
secondPass.push(item);
}
};
for(const item of secondPass) {
if(item.parent in map) {
if('children' in map[item.parent])
map[item.parent].children.push(item)
else
map[item.parent].children = [item];
}
};
return secondPass
}