MCPcopy
hub / github.com/marimo-team/marimo / reducer

Function reducer

frontend/src/components/ui/use-toast.ts:81–151  ·  view source on GitHub ↗
(state: State, action: Action)

Source from the content-addressed store, hash-verified

79};
80
81export const reducer = (state: State, action: Action): State => {
82 switch (action.type) {
83 case "ADD_TOAST":
84 return {
85 ...state,
86 toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),
87 };
88
89 case "UPDATE_TOAST":
90 return {
91 ...state,
92 toasts: state.toasts.map((t) =>
93 t.id === action.toast.id ? { ...t, ...action.toast } : t,
94 ),
95 };
96
97 case "DISMISS_TOAST": {
98 const { toastId } = action;
99
100 // ! Side effects ! - This could be extracted into a dismissToast() action,
101 // but I'll keep it here for simplicity
102 if (toastId) {
103 addToRemoveQueue(toastId);
104 } else {
105 state.toasts.forEach((toast) => {
106 addToRemoveQueue(toast.id);
107 });
108 }
109
110 return {
111 ...state,
112 toasts: state.toasts.map((t) =>
113 t.id === toastId || toastId === undefined
114 ? {
115 ...t,
116 open: false,
117 }
118 : t,
119 ),
120 };
121 }
122 case "REMOVE_TOAST":
123 if (action.toastId === undefined) {
124 return {
125 ...state,
126 toasts: [],
127 };
128 }
129 return {
130 ...state,
131 toasts: state.toasts.filter((t) => t.id !== action.toastId),
132 };
133 case "UPSERT_TOAST": {
134 const existingIndex = state.toasts.findIndex(
135 (t) => t.id === action.toast.id,
136 );
137 if (existingIndex > -1) {
138 return {

Callers 15

state.test.tsFile · 0.85
selection.test.tsFile · 0.85
dispatchFunction · 0.85
dispatchFunction · 0.85
reducerWithMiddlewareFunction · 0.85
useActionsFunction · 0.85
focus.test.tsFile · 0.85
addQueuedCellFunction · 0.85
runs.test.tsFile · 0.85
cells.test.tsFile · 0.85

Calls 5

addToRemoveQueueFunction · 0.85
sliceMethod · 0.80
forEachMethod · 0.80
filterMethod · 0.65
mapMethod · 0.45

Tested by 9

dispatchFunction · 0.68
addQueuedCellFunction · 0.68
dispatchFunction · 0.68
setupFunction · 0.68
addConnectionFunction · 0.68
filterDataSourcesFunction · 0.68
addSchemaListFunction · 0.68
addTableListFunction · 0.68
addTableFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…