Skip to content

Commit 5252ffa

Browse files
committed
Restore circular references
1 parent c19ed2e commit 5252ffa

File tree

6 files changed

+19
-27
lines changed

6 files changed

+19
-27
lines changed

packages/storage/compat/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { StringFormat } from '../src/implementation/string';
2121
import { TaskEvent, TaskState } from '../src/implementation/taskenums';
2222

2323
import { XhrIoPool } from '../src/implementation/xhriopool';
24-
import { ReferenceCompat as Reference, ReferenceCompat } from './reference';
24+
import { ReferenceCompat } from './reference';
2525
import { StorageServiceCompat } from './service';
2626
import { StorageService } from '../src/service';
2727
import * as types from '@firebase/storage-types';
@@ -51,8 +51,7 @@ function factory(
5151
// of creating a new one.
5252
const storageServiceCompat: StorageServiceCompat = new StorageServiceCompat(
5353
app,
54-
new StorageService(app, authProvider, new XhrIoPool(), url),
55-
ref => new ReferenceCompat(ref, storageServiceCompat)
54+
new StorageService(app, authProvider, new XhrIoPool(), url)
5655
);
5756
return storageServiceCompat;
5857
}
@@ -64,7 +63,7 @@ export function registerStorage(instance: _FirebaseNamespace): void {
6463
TaskEvent,
6564
StringFormat,
6665
Storage: StorageService,
67-
Reference
66+
Reference: ReferenceCompat
6867
};
6968
instance.INTERNAL.registerComponent(
7069
new Component(STORAGE_TYPE, factory, ComponentType.PUBLIC)

packages/storage/compat/list.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,23 @@
1818
import * as types from '@firebase/storage-types';
1919
import { ListResult } from '../src/list';
2020
import { ReferenceCompat } from './reference';
21-
import { Reference } from '../src/reference';
21+
import { StorageServiceCompat } from './service';
2222

2323
export class ListResultCompat implements types.ListResult {
2424
constructor(
2525
private readonly _delegate: ListResult,
26-
private _referenceConverter: (ref: Reference) => ReferenceCompat
26+
private readonly _service: StorageServiceCompat
2727
) {}
2828

2929
get prefixes(): ReferenceCompat[] {
30-
return this._delegate.prefixes.map(v => this._referenceConverter(v));
30+
return this._delegate.prefixes.map(
31+
ref => new ReferenceCompat(ref, this._service)
32+
);
3133
}
3234
get items(): ReferenceCompat[] {
33-
return this._delegate.items.map(v => this._referenceConverter(v));
35+
return this._delegate.items.map(
36+
ref => new ReferenceCompat(ref, this._service)
37+
);
3438
}
3539
get nextPageToken(): string | null {
3640
return this._delegate.nextPageToken || null;

packages/storage/compat/reference.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ export class ReferenceCompat implements types.Reference {
139139
*/
140140
listAll(): Promise<types.ListResult> {
141141
return listAll(this._delegate).then(
142-
r =>
143-
new ListResultCompat(r, ref => new ReferenceCompat(ref, this.storage))
142+
r => new ListResultCompat(r, this.storage)
144143
);
145144
}
146145

@@ -165,8 +164,7 @@ export class ReferenceCompat implements types.Reference {
165164
*/
166165
list(options?: ListOptions | null): Promise<types.ListResult> {
167166
return list(this._delegate, options).then(
168-
r =>
169-
new ListResultCompat(r, ref => new ReferenceCompat(ref, this.storage))
167+
r => new ListResultCompat(r, this.storage)
170168
);
171169
}
172170

packages/storage/compat/service.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import * as types from '@firebase/storage-types';
1919
import { StorageService, isUrl, ref } from '../src/service';
2020
import { Location } from '../src/implementation/location';
2121
import { ReferenceCompat } from './reference';
22-
import { Reference } from '../src/reference';
2322
import { invalidArgument } from '../src/implementation/error';
2423
import { FirebaseApp } from '@firebase/app-types';
2524

@@ -28,11 +27,7 @@ import { FirebaseApp } from '@firebase/app-types';
2827
* @param opt_url gs:// url to a custom Storage Bucket
2928
*/
3029
export class StorageServiceCompat implements types.FirebaseStorage {
31-
constructor(
32-
public app: FirebaseApp,
33-
readonly _delegate: StorageService,
34-
private _referenceConverter: (ref: Reference) => ReferenceCompat
35-
) {}
30+
constructor(public app: FirebaseApp, readonly _delegate: StorageService) {}
3631

3732
INTERNAL = {
3833
/**
@@ -61,7 +56,7 @@ export class StorageServiceCompat implements types.FirebaseStorage {
6156
'ref() expected a child path but got a URL, use refFromURL instead.'
6257
);
6358
}
64-
return this._referenceConverter(ref(this._delegate, path));
59+
return new ReferenceCompat(ref(this._delegate, path), this);
6560
}
6661

6762
/**
@@ -81,7 +76,7 @@ export class StorageServiceCompat implements types.FirebaseStorage {
8176
'refFromUrl() expected a valid full URL but got an invalid one.'
8277
);
8378
}
84-
return this._referenceConverter(ref(this._delegate, url));
79+
return new ReferenceCompat(ref(this._delegate, url), this);
8580
}
8681

8782
setMaxUploadRetryTime(time: number): void {

packages/storage/test/unit/reference.compat.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ function makeFakeService(
3737
): StorageServiceCompat {
3838
const storageServiceCompat: StorageServiceCompat = new StorageServiceCompat(
3939
app,
40-
new StorageService(app, authProvider, testShared.makePool(sendHook)),
41-
ref => new ReferenceCompat(ref, storageServiceCompat)
40+
new StorageService(app, authProvider, testShared.makePool(sendHook))
4241
);
4342
return storageServiceCompat;
4443
}
@@ -51,8 +50,7 @@ function makeStorage(url: string): ReferenceCompat {
5150
);
5251
const storageServiceCompat: StorageServiceCompat = new StorageServiceCompat(
5352
{} as FirebaseApp,
54-
service,
55-
ref => new ReferenceCompat(ref, storageServiceCompat)
53+
service
5654
);
5755
return new ReferenceCompat(new Reference(service, url), storageServiceCompat);
5856
}

packages/storage/test/unit/service.compat.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import * as testShared from './testshared';
2222
import { DEFAULT_HOST } from '../../src/implementation/constants';
2323
import { FirebaseStorageError } from '../../src/implementation/error';
2424
import { StorageService } from '../../src/service';
25-
import { ReferenceCompat } from '../../compat/reference';
2625
import { FirebaseApp } from '@firebase/app-types';
2726
import { Provider } from '@firebase/component';
2827
import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
@@ -44,8 +43,7 @@ function makeService(
4443
): StorageServiceCompat {
4544
const storageServiceCompat: StorageServiceCompat = new StorageServiceCompat(
4645
app,
47-
new StorageService(app, authProvider, pool, url),
48-
ref => new ReferenceCompat(ref, storageServiceCompat)
46+
new StorageService(app, authProvider, pool, url)
4947
);
5048
return storageServiceCompat;
5149
}

0 commit comments

Comments
 (0)