Function
update
(key: Key, newValue: T | ((prev: T) => T))
Source from the content-addressed store, hash-verified
| 368 | }); |
| 369 | }, |
| 370 | update(key: Key, newValue: T | ((prev: T) => T)) { |
| 371 | dispatch(state => { |
| 372 | let index = state.items.findIndex(item => getKey!(item) === key); |
| 373 | if (index === -1) { |
| 374 | return state; |
| 375 | } |
| 376 | |
| 377 | let updatedValue: T; |
| 378 | if (typeof newValue === 'function') { |
| 379 | updatedValue = (newValue as (prev: T) => T)(state.items[index]); |
| 380 | } else { |
| 381 | updatedValue = newValue; |
| 382 | } |
| 383 | |
| 384 | return { |
| 385 | ...state, |
| 386 | items: [...state.items.slice(0, index), updatedValue, ...state.items.slice(index + 1)] |
| 387 | }; |
| 388 | }); |
| 389 | } |
| 390 | }; |
| 391 | } |
| 392 | |
Callers
nothing calls this directly
Tested by
no test coverage detected