Repository navigation
Batch operations #48
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or request
Milestone
Description
Context
core.add and core.remove work one entity at a time, and each call emits its own entities:changed event. Loading 1,000 entities emits 1,000 events, and each one triggers a full repaint in the SVG renderer (see #47). Deleting a multi-selection has the same problem.
core.updateMany already exists and emits a single { type: 'update', ids } event. This issue adds the same for add and remove, and a generic batch for mixed changes.
What changes
New methods on SpatialCore:
core.addMany(entities: Entity[]): void; // one { type: 'add', ids } event
core.removeMany(ids: EntityId[]): void; // one { type: 'remove', ids } event
// + one selection:change if any removed id was selectedOptional: a generic batch. It collects every change made inside the callback and emits at most one event per type at the end:
core.batch(() => {
core.add(a);
core.update(b.id, { bounds });
core.remove(c.id);
});
// emits: add [a], update [b], remove [c] — once each, after the callbackProposal: ship addMany and removeMany first (small and clear), and discuss batch in the comments. Nested batches and errors thrown inside the callback need a decision.
Affected files
| File | Change |
|---|---|
packages/core/src/core.ts |
addMany, removeMany (and possibly batch) |
packages/core/src/__tests__/ |
Tests for the new methods |
packages/core/README.md |
Document them next to updateMany |
Invariants to preserve
- Event payload shapes do not change:
{ type, ids }and{ selection }. - Empty input emits no event, the same as
updateManytoday. removeManyremoves ids from the selection, the same asremove.- Insertion order is preserved by
addMany(it defines z-order). - No production dependencies; core stays framework-agnostic.
Implementation checklist
-
addManywith tests (one event, ids in order, empty input) -
removeManywith tests (one event, selection updated with oneselection:change, unknown ids ignored) - Docs in the core README
- Changeset (
minorfor core) - Run
pnpm typecheck && pnpm test && pnpm lint - Optional: discuss and implement
batch(may be a follow-up issue)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Activity