Skip to content

Commit ab9c64a

Browse files
committed
Wrap nextOrObserver for compat
1 parent bd3dac2 commit ab9c64a

File tree

2 files changed

+25
-62
lines changed

2 files changed

+25
-62
lines changed

common/api-review/storage.api.md

Lines changed: 0 additions & 60 deletions
This file was deleted.

packages/storage/compat/task.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,33 @@ export class UploadTaskCompat implements types.UploadTask {
6969
error?: ErrorFn | null,
7070
completed?: CompleteFn | null
7171
): Unsubscribe | Subscribe<UploadTaskSnapshotCompat> {
72-
// TODO: Wrap all returned values in new snapshot
72+
let wrappedNextOrObserver:
73+
| StorageObserver<UploadTaskSnapshot>
74+
| undefined
75+
| ((a: UploadTaskSnapshot) => unknown) = undefined;
76+
if (nextOrObserver != null) {
77+
if (typeof nextOrObserver === 'function') {
78+
wrappedNextOrObserver = (taskSnapshot: UploadTaskSnapshot) =>
79+
nextOrObserver(
80+
new UploadTaskSnapshotCompat(taskSnapshot, this, this._ref)
81+
);
82+
} else {
83+
wrappedNextOrObserver = {
84+
next:
85+
nextOrObserver.next == null
86+
? undefined
87+
: (taskSnapshot: UploadTaskSnapshot) =>
88+
nextOrObserver.next!(
89+
new UploadTaskSnapshotCompat(taskSnapshot, this, this._ref)
90+
),
91+
complete: nextOrObserver.complete || undefined,
92+
error: nextOrObserver.error || undefined
93+
};
94+
}
95+
}
7396
return this._delegate.on(
7497
type,
75-
(nextOrObserver || undefined) as StorageObserver<UploadTaskSnapshot>,
98+
wrappedNextOrObserver,
7699
error || undefined,
77100
completed || undefined
78101
);

0 commit comments

Comments
 (0)