Makes the reducer a bit more debuggable

This commit is contained in:
2025-10-11 15:00:48 -07:00
parent f8aac31306
commit f197a3fabe

View File

@@ -137,6 +137,7 @@ export function reducer(
state: DocumentState,
action: DocumentAction,
): DocumentState {
console.debug("Processing action", action);
switch (action.type) {
case "loadingDocument":
return setLoadingDocument(action.docId, state);
@@ -145,15 +146,17 @@ export function reducer(
case "setRelationship":
return setRelationship(action.docId, state, action.relationship);
case "setDocumentTree":
const updatedDocumentState = setAllRelationshipsEmpty(
action.doc.id,
setDocument(state, action.doc),
);
const updatedRelationshipsState = action.relationships.reduce(
setRelationship.bind(null, action.doc.id),
updatedDocumentState,
);
return action.relatedDocuments.reduce(
setDocument,
action.relationships.reduce(
setRelationship.bind(null, action.doc.id),
setAllRelationshipsEmpty(
action.doc.id,
setDocument(state, action.doc),
),
),
updatedRelationshipsState,
);
case "removeDocument":
return removeDocument(action.docId, state);