@inglorious/store 11.0.0 → 11.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@inglorious/store",
3
- "version": "11.0.0",
3
+ "version": "11.0.1",
4
4
  "description": "A state manager for real-time, collaborative apps, inspired by game development patterns and compatible with Redux.",
5
- "author": "IceOnFire <antony.mistretta@gmail.com> (https://ingloriouscoderz.it)",
5
+ "author": "Matteo Antony Mistretta <antony.mistretta@gmail.com> (https://ingloriouscoderz.it)",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
@@ -55,18 +55,18 @@
55
55
  },
56
56
  "sideEffects": false,
57
57
  "dependencies": {
58
- "mutative": "^1.3.0",
59
- "@inglorious/utils": "3.8.0"
58
+ "@inglorious/utils": "3.8.0",
59
+ "mutative": "^1.3.0"
60
60
  },
61
61
  "peerDependencies": {
62
62
  "@inglorious/utils": "3.8.0"
63
63
  },
64
64
  "devDependencies": {
65
+ "@inglorious/eslint-config": "1.1.2",
65
66
  "@reduxjs/toolkit": "^2.11.2",
66
67
  "prettier": "^3.6.2",
67
68
  "vite": "^7.1.3",
68
- "vitest": "^1.6.1",
69
- "@inglorious/eslint-config": "1.1.2"
69
+ "vitest": "^1.6.1"
70
70
  },
71
71
  "engines": {
72
72
  "node": ">= 22"
package/src/async.js CHANGED
@@ -162,13 +162,16 @@ export function handleAsync(type, handlers, options = {}) {
162
162
  }),
163
163
 
164
164
  async [`${type}Run`](entity, payload, api) {
165
+ // Snapshot routing keys before await — mutative revokes draft proxies after the patch.
166
+ const scopedEntity = { id: entity.id, type: entity.type }
167
+
165
168
  try {
166
169
  const result = await handlers.run(payload, api)
167
- notify(api, entity, `${type}Success`, result)
170
+ notify(api, scopedEntity, `${type}Success`, result)
168
171
  } catch (error) {
169
- notify(api, entity, `${type}Error`, error)
172
+ notify(api, scopedEntity, `${type}Error`, error)
170
173
  } finally {
171
- notify(api, entity, `${type}Finally`)
174
+ notify(api, scopedEntity, `${type}Finally`)
172
175
  }
173
176
  },
174
177
 
package/src/store.js CHANGED
@@ -244,6 +244,9 @@ export function createStore({
244
244
  const entitiesToDestroy = [...oldEntityIds].filter(
245
245
  (id) => !newEntityIds.has(id),
246
246
  )
247
+ const entitiesToUpdate = [...newEntityIds].filter((id) =>
248
+ oldEntityIds.has(id),
249
+ )
247
250
 
248
251
  state = oldEntities
249
252
  eventMap = new EventMap(types, oldEntities)
@@ -259,6 +262,17 @@ export function createStore({
259
262
  addEntity(state, { id, ...entity })
260
263
  })
261
264
 
265
+ entitiesToUpdate.forEach((id) => {
266
+ const oldType = oldEntities[id].type
267
+ const newEntity = newEntities[id]
268
+ state[id] = newEntity
269
+
270
+ if (newEntity.type !== oldType) {
271
+ eventMap.removeEntity(id, types[oldType], oldType)
272
+ eventMap.addEntity(id, types[newEntity.type], newEntity.type)
273
+ }
274
+ })
275
+
262
276
  if (autoCreateEntities) {
263
277
  for (const typeName of Object.keys(types)) {
264
278
  const entityId = toCamelCase(typeName)