const groupBy = (collection, extractKey) =>
collection.reduce((acc, item) => {
const key = extractKey(item);
acc[key] ??= [];
acc[key].push(item);
return acc;
}, {});
const data = groupBy(array, (person) => person.role);
Object.groupBy(array, (person) => person.role);
<div class="scroll-blocker">
<YOUR_MAP />
</div>
const mouse = { x: -1, y: -1 };
const elements = document.getElementsByClassName('scroll-blocker');
window.addEventListener('mousemove', (event) => {
mouse.x = event.clientX;
mouse.y = event.clientY;
});
window.addEventListener('wheel', (event) => {
const target = document.elementFromPoint(mouse.x, mouse.y);
for (const element of elements) {
if (element.contains(target)) {
event.preventDefault();
return;
}
}
}, { passive: false, capture: true });
const input = document.querySelector('input');
input.addEventListener('input', (event) => {
const value = event.target.value
.replace(/^\+?[78]/, '')
.replace(/[^0-9]/g, '')
.slice(0, 10);
event.target.value = value;
});
IMask(document.querySelector('input'), { mask: '000 000 00 00' });
$(document).on('click', '.content .child', function(event){
event.stopPropagation();
});
const response = await fetch('data.json');
const data = await response.json();
console.log(data);
npx
, например: npx serve
. const updateItems = async ({ id, isShow = false }: Partial<{ id: number, isShow: boolean }>) => {};
document.documentElement
.data-theme="dark"
localStorage
:localStorage.setItem('theme', isChecked ? 'dark' : 'light');
head
добавляйте скрипт, который применит атрибут:const theme = localStorage.getItem('theme');
if (mode === 'dark') {
document.documentElement.dataset.theme = 'dark';
}
Object.fromEntries(Object.entries(...).map(([key, value]) => [key, [value]]));
Function.prototype.apply()
принимает первым аргументом контекст (this
), с которым будет работать, в Вашем случае - person
. Вторым аргументом принимает массив аргументов вызова функции, которую вызываете при помощи .apply
. Можете почитать подробнее на MDN и learn.javascript.ru. render
. Что-то вроде:const createPath = (x, y) => {
const path = new Path2D();
path.roundRect(x, y, 200, 40, 30);
return path;
};
let taskList = [
{ id: 0, value: "", x: 150, y: 75 },
{ id: 0, value: "", x: -150, y: 75 },
].map((entry) => ({ ...entry, path: createPath(entry.x, entry.y) }));
render
.let cameraX = 0;
let cameraY = 0;
addEventListener("mousemove", ({ button, clientX, clientY }) => {
if (pressMM) {
cameraX += clientX - lastX;
cameraY += clientY - lastY;
lastX = clientX;
lastY = clientY;
}
});
const drawTasks = () => {
context.clearRect(0, 0, canvas.width, canvas.height);
context.save();
context.translate(cameraX, cameraY);
for (const { x, y, path, value } of taskList) {
context.beginPath();
context.stroke(path);
}
context.restore();
};