-
-
Notifications
You must be signed in to change notification settings - Fork 202
feat: Implement 'internalId' via Collection Identity Hook #9070
Copy link
Copy link
Closed
Labels
coreCore framework functionalityCore framework functionalityenhancementNew feature or requestNew feature or request
Description
Context:
Currently, Neo.mjs relies on the record's primary key (keyProperty) for DOM element IDs (e.g., view__1). This presents several challenges:
- Phantom Records: New records have no ID (
null), causing DOM ID collisions (view__null). - DOM Security: Exposing database IDs in the DOM allows for enumeration attacks.
- Stability: Saving a record changes its ID (e.g.,
-1->100), forcing a destructive DOM update. - Cross-Store Uniqueness: Drag-and-drop between stores can lead to ID collisions if different entities share the same PK.
Objective:
Implement a stable, globally unique internalId (e.g., neo-record-1) for all data items (Records and Raw Objects), maintained via a lightweight Symbol property.
Architecture: The "Identity Provider" Pattern
To maintain the separation of concerns between Neo.collection.Base (dumb container) and Neo.data.Store (smart data manager), we will introduce an itemFactory hook.
Implementation Plan:
-
Define Symbol:
- Create
src/util/Symbol.mjs(or similar) to exportconst internalId = Symbol.for('neoInternalId');.
- Create
-
Enhance
Neo.collection.Base:- Add
itemFactoryconfig (Function). - Inside the
splicemethod's addition loop, invoke the hook:me.itemFactory?.(item);
- Documentation: Add intent-driven JSDoc explaining this is an injection point for item augmentation (like identity) without requiring inheritance.
- Add
-
Update
Neo.data.Store:- Implement
assignInternalId(item)method. - In
construct, bind this method to theitemFactoryconfig. - Logic:
if (!item[internalId]) { item[internalId] = Neo.getId('record'); }
- Implement
-
Update
Neo.data.RecordFactory:- Ensure created Records also receive this symbol during instantiation.
-
Expose Accessor:
- Add
store.getInternalId(item)helper.
- Add
Outcome:
- Zero Iteration Overhead: Piggybacks on the existing Collection map generation loop.
- Decoupled: Collection remains ignorant of "Records".
- Secure & Stable: Provides the foundation for immutable DOM identities.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
coreCore framework functionalityCore framework functionalityenhancementNew feature or requestNew feature or request