(id, input)
| 200 | items, |
| 201 | sortItems, |
| 202 | update(id, input) { |
| 203 | const entity = itemsMap[id]; |
| 204 | |
| 205 | if (!entity) { |
| 206 | throw new Error( |
| 207 | `Entity "${definition.config.name}" with id "${id}" not found` |
| 208 | ); |
| 209 | } |
| 210 | |
| 211 | const changes = computeChanges(entity, input); |
| 212 | const changedKeys = typedKeys(changes); |
| 213 | |
| 214 | if (changedKeys.includes(config.idField!)) { |
| 215 | throw new Error( |
| 216 | `Cannot update id field of entity "${definition.config.name}"` |
| 217 | ); |
| 218 | } |
| 219 | |
| 220 | // No changes will be made, return early |
| 221 | if (!changedKeys.length) |
| 222 | return { |
| 223 | changes, |
| 224 | db, |
| 225 | entity, |
| 226 | type: "updated", |
| 227 | rollback: () => void 0, |
| 228 | }; |
| 229 | |
| 230 | const changedData: Partial<Data> = {}; |
| 231 | |
| 232 | function rollback() { |
| 233 | const undoInput = pickBeforeFromChanges(changes); |
| 234 | store.update(id, undoInput); |
| 235 | } |
| 236 | |
| 237 | runInAction(() => { |
| 238 | changedKeys.forEach((keyToUpdate) => { |
| 239 | const value = input[keyToUpdate]; |
| 240 | (entity as Data)[keyToUpdate] = value!; |
| 241 | changedData[keyToUpdate] = value; |
| 242 | }); |
| 243 | updateEntityIndexes(entity, changedKeys); |
| 244 | }); |
| 245 | |
| 246 | return { |
| 247 | changes, |
| 248 | db, |
| 249 | entity, |
| 250 | rollback, |
| 251 | type: "updated", |
| 252 | }; |
| 253 | }, |
| 254 | getPropIndex(key) { |
| 255 | const existingIndex = propIndexMap.get(key); |
| 256 |
nothing calls this directly
no test coverage detected