Skip to content

Commit 57d1760

Browse files
committed
feat(File): added updateDocumentObj method for updating documentObj
1 parent e06669f commit 57d1760

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/data/file.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,17 @@ export class File implements FileLike {
170170
this.dispatchEvent('ondocumentobjchange');
171171
}
172172

173+
/**
174+
* Use this file to make updates to `documentObj` that you want reflected in
175+
* `fileObj` and `thumbnail`. Since mutations directly to `documentObj` will
176+
* not be detected, using this function tells `File` to trigger an update.
177+
*/
178+
async updateDocumentObj(updater: (documentObj: CoreControls.Document) => Promise<void>) {
179+
const documentObj = await this.documentObj.get();
180+
await updater(documentObj);
181+
this.setDocumentObj(documentObj);
182+
}
183+
173184
/* --- File utility functions. --- */
174185

175186
/**
@@ -189,10 +200,10 @@ export class File implements FileLike {
189200
*/
190201
clone() {
191202
return new File({
192-
name: this._name,
193-
originalName: this._originalName,
194-
extension: this._extension,
195-
documentObj: blobToDocument(documentToBlob(this._documentObj.get()), this._extension),
203+
name: this.name,
204+
originalName: this.originalName,
205+
extension: this.extension,
206+
documentObj: blobToDocument(documentToBlob(this.documentObj.get()), this.extension),
196207
});
197208
}
198209

0 commit comments

Comments
 (0)