From f197a3fabefde99948088c82e46751214aa0c2fb Mon Sep 17 00:00:00 2001 From: Drew Haven Date: Sat, 11 Oct 2025 15:00:48 -0700 Subject: [PATCH] Makes the reducer a bit more debuggable --- src/context/document/reducer.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/context/document/reducer.ts b/src/context/document/reducer.ts index 049eb31..968989d 100644 --- a/src/context/document/reducer.ts +++ b/src/context/document/reducer.ts @@ -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);