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