Object.fromEntries(Object.entries(...).map(([key, value]) => [key, [value]]));
type Branch<T> = {
data: T;
children: Branch<T>[];
};
type Tree<T> = Branch<T>[];
const createTree = <T, K>(
collection: T[],
extractId: (entry: T) => K,
extractParentId: (entry: T) => K | null
): Tree<T> => {
const cache = new Map<K, Branch<T>>();
const tree: Tree<T> = [];
for (const entry of collection) {
const id = extractId(entry);
const parentId = extractParentId(entry);
const branch: Branch<T> = {
data: entry,
children: []
};
const root =
parentId !== null ? cache.get(parentId)?.children ?? tree : tree;
root.push(branch);
cache.set(id, branch);
}
return tree;
};
const tree = createTree(
item_list,
(entry) => entry.id,
(entry) => entry.parentId
);
base
- пример.homepage
.Function.prototype.apply()
принимает первым аргументом контекст (this
), с которым будет работать, в Вашем случае - person
. Вторым аргументом принимает массив аргументов вызова функции, которую вызываете при помощи .apply
. Можете почитать подробнее на MDN и learn.javascript.ru. <div className="reference-container">
<div className="reference-container-panel">
{isToolsVisible && <div className="tools"></div>}
{isSeracpPanleVisible && <div className="searchPanel"</div>}
</div>
<div className="mainContent"></div>
</div>
.reference-container {
height: 100%;
display: grid;
grid-template-rows: max-content 1fr;
}
.reference-container-panel {
display: grid;
grid-auto-rows: max-content;
}
.reference-container-panel:empty {
display: none;
}
.tools {
height: 100px;
}
.searchPanel {
height: 50px;
}
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();
};
import gulp from 'gulp';
import imagemin from 'gulp-imagemin';
export default () => (
gulp.src('src/images/*')
.pipe(imagemin())
.pipe(gulp.dest('dist/images'))
);