MCPcopy Index your code
hub / github.com/mitmproxy/mitmproxy / updateState

Function updateState

web/src/js/ducks/modes/reverse.ts:59–110  ·  view source on GitHub ↗
(
            state: ReverseState[],
            action: PayloadAction<Partial<BackendState>>,
        )

Source from the content-addressed store, hash-verified

57 builder.addCase(STATE_RECEIVE, updateState);
58 builder.addCase(STATE_UPDATE, updateState);
59 function updateState(
60 state: ReverseState[],
61 action: PayloadAction<Partial<BackendState>>,
62 ) {
63 if (action.payload.servers) {
64 // action.data.servers does not include servers that are currently inactive,
65 // but we want to keep them in the UI. So we need to merge UI state with what we got from the server.
66
67 const activeServers = Object.fromEntries(
68 Object.entries(action.payload.servers)
69 .filter(([_, info]) => info.type === "reverse")
70 .map(([spec, _]) => [spec, parseSpec(spec)]),
71 );
72
73 const nextState: ReverseState[] = [];
74
75 // keep current UI state as is, but correct `active` bit.
76 for (const server of state) {
77 const spec = getSpec(server);
78 const active = spec in activeServers;
79 delete activeServers[spec];
80 nextState.push({
81 ...server,
82 active,
83 });
84 }
85
86 // add all new specs
87 for (const x of Object.values(activeServers)) {
88 nextState.push(parseRaw(x));
89 }
90
91 // remove default config if still present.
92 if (
93 nextState.length > 1 &&
94 shallowEqual(
95 {
96 ...nextState[0],
97 ui_id: undefined,
98 } as ReverseState,
99 {
100 ...defaultReverseState(),
101 ui_id: undefined,
102 } as ReverseState,
103 )
104 ) {
105 nextState.shift();
106 }
107
108 return nextState;
109 }
110 }
111 },
112});
113export const { addServer, removeServer } = reverseSlice.actions;

Callers

nothing calls this directly

Calls 9

parseSpecFunction · 0.90
getSpecFunction · 0.90
parseRawFunction · 0.90
defaultReverseStateFunction · 0.90
valuesMethod · 0.80
shiftMethod · 0.80
mapMethod · 0.45
filterMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…