import {Part} from "./part"; import {Immutable} from "mutative"; export function createPartsFromTable(items: readonly T[], getId: (item: T, index: number) => string, getCount?: ((item: T) => number) | number){ const pool: Record> = {}; for (const entry of items) { const count = getCount ? (typeof getCount === 'function' ? getCount(entry) : getCount) : 1; for (let i = 0; i < count; i++) { const id = getId(entry, i); pool[id] = { id, regionId: '', position: [], ...entry as Immutable }; } } return pool; } export function createParts(item: T, getId: (index: number) => string, count?: number){ return createPartsFromTable([item], (_,index) => getId(index), count); }