Skip to content

Commit

Permalink
clean up missing doc handling
Browse files Browse the repository at this point in the history
  • Loading branch information
pvh committed Jan 31, 2025
1 parent 6d5d5e5 commit 28876d4
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions packages/automerge-repo/src/Repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,6 @@ export class Repo extends EventEmitter<RepoEvents> {
* Any peers this `Repo` is connected to for whom `sharePolicy` returns `true` will
* be notified of the newly created DocHandle.
*
* @throws if the cloned handle is not yet ready or if
* `clonedHandle.doc()` returns `undefined` (i.e. the handle is unavailable).
*/
clone<T>(clonedHandle: DocHandle<T>) {
if (!clonedHandle.isReady()) {
Expand All @@ -406,10 +404,6 @@ export class Repo extends EventEmitter<RepoEvents> {
}

const sourceDoc = clonedHandle.doc()
if (!sourceDoc) {
throw new Error("Cloned handle doesn't have a document.")
}

const handle = this.create<T>()

handle.update(() => {
Expand Down Expand Up @@ -690,11 +684,7 @@ export class Repo extends EventEmitter<RepoEvents> {
: Object.values(this.#handleCache)
await Promise.all(
handles.map(async handle => {
const doc = handle.doc()
if (!doc) {
return
}
return this.storageSubsystem!.saveDoc(handle.documentId, doc)
return this.storageSubsystem!.saveDoc(handle.documentId, handle.doc())
})
)
}
Expand All @@ -715,6 +705,7 @@ export class Repo extends EventEmitter<RepoEvents> {
const handle = this.#getHandle({ documentId })
await handle.whenReady([READY, UNLOADED, DELETED, UNAVAILABLE])
const doc = handle.doc()
// because this is an internal-ish function, we'll be extra careful about undefined docs here
if (doc) {
if (handle.isReady()) {
handle.unload()
Expand Down

0 comments on commit 28876d4

Please sign in to comment.