Frontmatter
| id | 8077 |
| title | Enhance Store DX: Add initRecord() to return Model instance on add |
| state | Closed |
| labels | enhancementdeveloper-experienceai |
| assignees | tobiu |
| createdAt | Dec 10, 2025, 11:34 AM |
| updatedAt | Dec 10, 2025, 11:59 AM |
| githubUrl | https://github.com/neomjs/neo/issues/8077 |
| author | tobiu |
| commentsCount | 1 |
| parentIssue | null |
| subIssues | [] |
| subIssuesCompleted | 0 |
| subIssuesTotal | 0 |
| blockedBy | [] |
| blocking | [] |
| closedAt | Dec 10, 2025, 11:59 AM |
Enhance Store DX: Add initRecord() to return Model instance on add
tobiu assigned to @tobiu on Dec 10, 2025, 11:35 AM

tobiu
Dec 10, 2025, 11:52 AM
Input from Neo.mjs Agent:
◆ I have implemented the fix with a slight variation from the original proposal to improve code clarity and safety.
Implementation Details:
Neo.data.Store: Added theinitRecord(data)method.
- It does not call
add(). Instead, it assumes the data is already present in the store (as a plain object), looks up its key usinggetKeyProperty(), and returns the fully instantiatedModelviaget().- This separates the concern of "adding data" from "initializing a record".
Neo.calendar.view.week.plugin.DragDrop:
- In
onColumnDragStart, I introduced a new variablerecordDatato hold the plain object returned byowner.eventStore.add().- This prevents shadowing the method's
dataargument (which contains the drag event info).- I then call
record = owner.eventStore.initRecord(recordData)to obtain the record instance required byEventDragZone.Code Changes:
src/data/Store.mjs:/** * Adds a new item to the store and immediately returns its record instance. * @param {Object} data The data object to add * @returns {Neo.data.Model} The created record */ initRecord(data) { return this.get(data[this.getKeyProperty()]) }
src/calendar/view/week/plugin/DragDrop.mjs:// ... recordData = owner.eventStore.add({ // ... })[0];record = owner.eventStore.initRecord(recordData); // ...
tobiu closed this issue on Dec 10, 2025, 11:59 AM
Improve Developer Experience (DX) when working with
lazy recordsinNeo.data.Store.Currently, adding a new record requires two steps to get the
Modelinstance:store.add(data)(returns the plain data object).store.get(id)(returns theModelinstance).Proposal: Add a new method
initRecord(data)toNeo.data.Storethat combines these steps:initRecord(data) { // Implementation concept const items = this.add(data); const item = Array.isArray(items) ? items[0] : items; return this.get(item[this.keyProperty]); }Refactoring: Update
src/calendar/view/week/plugin/DragDrop.mjs:recordvariable todata(since it starts as a plain object).const record = owner.eventStore.initRecord(data)to create the event.