(
builder: ActionReducerMapBuilder<M[]>,
attribute: Attr,
setThunk: AsyncThunk<
void,
{ server: ModeState; value: Draft<M>[Attr] },
AppAsyncThunkConfig
>,
)
| 57 | } |
| 58 | |
| 59 | export function addSetter<M extends ModeState, Attr extends keyof Draft<M>>( |
| 60 | builder: ActionReducerMapBuilder<M[]>, |
| 61 | attribute: Attr, |
| 62 | setThunk: AsyncThunk< |
| 63 | void, |
| 64 | { server: ModeState; value: Draft<M>[Attr] }, |
| 65 | AppAsyncThunkConfig |
| 66 | >, |
| 67 | ) { |
| 68 | builder.addCase(setThunk.pending, (state, action) => { |
| 69 | const { server, value } = action.meta.arg; |
| 70 | const idx = state.findIndex((m) => m.ui_id === server.ui_id); |
| 71 | if (idx >= 0) { |
| 72 | state[idx][attribute] = value; |
| 73 | state[idx].error = undefined; |
| 74 | } |
| 75 | }); |
| 76 | builder.addCase(setThunk.rejected, (state, action) => { |
| 77 | const { server } = action.meta.arg; |
| 78 | const idx = state.findIndex((m) => m.ui_id === server.ui_id); |
| 79 | if (idx >= 0) { |
| 80 | state[idx].error = action.error.message; |
| 81 | } |
| 82 | }); |
| 83 | } |
| 84 | |
| 85 | export function updateState<M extends ModeState>( |
| 86 | type: string, |
no test coverage detected
searching dependent graphs…