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

Function flowsReducer

web/src/js/ducks/flows/index.ts:75–317  ·  view source on GitHub ↗
(
    state = defaultState,
    action: UnknownAction,
)

Source from the content-addressed store, hash-verified

73// This is racy: We may see flows/add events for flows that are already in the view, or update/remove events
74// for flows that aren't known at all. The reducer needs to handle these cases gracefully.
75export default function flowsReducer(
76 state = defaultState,
77 action: UnknownAction,
78): FlowsState {
79 if (FLOWS_RECEIVE.match(action)) {
80 const { sort } = state;
81 const list = action.payload;
82 const _listIndex = buildIndex(list);
83 const byId = new Map(list.map((f) => [f.id, f]));
84 // No filter information yet, we expect that to come immediately after.
85 const view = toSorted(list, makeSort(sort));
86 const _viewIndex = buildIndex(view);
87 const selected = state.selected
88 .map((flow) => byId.get(flow.id))
89 .filter((f) => f !== undefined);
90 const selectedIds = buildLookup(selected);
91 const highlightedIds = new Set<string>();
92
93 return {
94 list,
95 _listIndex,
96 byId,
97 view,
98 _viewIndex,
99 sort,
100 selected,
101 selectedIds,
102 highlightedIds,
103 };
104 } else if (FLOWS_ADD.match(action)) {
105 const { flow, matching_filters } = action.payload;
106 if (state._listIndex.has(flow.id)) {
107 return state; // WebSocket/HTTP race
108 }
109 const { sort, selected, selectedIds } = state;
110 let { view, _viewIndex, highlightedIds } = state;
111 // Update list
112 const _listIndex = new Map(state._listIndex);
113 _listIndex.set(flow.id, state.list.length);
114 const list = [...state.list, flow];
115 const byId = new Map(state.byId);
116 byId.set(flow.id, flow);
117 // Update view if filter matches (true) or is unset (undefined).
118 if (
119 matching_filters[FilterName.Search] === true ||
120 matching_filters[FilterName.Search] === undefined
121 ) {
122 ({ view, _viewIndex } = insertViewItem(
123 view,
124 _viewIndex,
125 flow,
126 makeSort(sort),
127 ));
128 }
129 // Update highlight
130 if (matching_filters[FilterName.Highlight] === true) {
131 highlightedIds = new Set(highlightedIds);
132 highlightedIds.add(flow.id);

Callers

nothing calls this directly

Calls 15

buildIndexFunction · 0.90
toSortedFunction · 0.90
buildLookupFunction · 0.90
insertViewItemFunction · 0.90
removeViewItemAtFunction · 0.90
updateViewItemFunction · 0.90
withElemRemovedFunction · 0.90
toSplicedFunction · 0.90
assertNeverFunction · 0.90
makeSortFunction · 0.85
matchMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…