I'm currently working on an Angular app. Within my service, DocumentService
, I have a BehaviorSubject
that holds an array of Documents.
documents: BehaviorSubject<Document[]>
Let me provide you with some insight into the various classes I've created:
class Document {
title: string
files: File[];
}
class File {
pages: Page[];
}
class Page {
content: any;
resolution: number;
}
Now, here's my dilemma - what is the most effective way to update the resolution property within a page? To achieve this, I need to navigate through the document, access the file, and then reach the specific page for modification. Unfortunately, directly updating in place isn't an option due to the requirement of using
this.documents.next(newDocumentsArray)
. I've tried deep copying methods like JSON.parse(JSON.stringify(...))
, but encountered issues with circular structures. Other techniques such as .map
and Object.assign
only provide shallow copies that end up modifying the page directly, which is not permissible in this case.
Any suggestions or advice would be greatly appreciated. Thank you!