Skip to content

Commit 6129d07

Browse files
committed
make compat work in runtime
1 parent 1f5ed0e commit 6129d07

File tree

5 files changed

+69
-48
lines changed

5 files changed

+69
-48
lines changed

packages/storage/compat/index.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@ import { _FirebaseNamespace } from '@firebase/app-types/private';
2020
import { StringFormat } from '../src/implementation/string';
2121
import { TaskEvent, TaskState } from '../src/implementation/taskenums';
2222

23-
import { XhrIoPool } from '../src/implementation/xhriopool';
2423
import { ReferenceCompat } from './reference';
2524
import { StorageServiceCompat } from './service';
26-
import { StorageService } from '../src/service';
2725
import * as types from '@firebase/storage-types';
2826
import {
2927
Component,
@@ -34,6 +32,8 @@ import {
3432

3533
import { name, version } from '../package.json';
3634

35+
import '../register-module';
36+
3737
/**
3838
* Type constant for Firebase Storage.
3939
*/
@@ -44,21 +44,16 @@ function factory(
4444
{ instanceIdentifier: url }: InstanceFactoryOptions
4545
): types.FirebaseStorage {
4646
// Dependencies
47-
// TODO: This should eventually be 'app-compat'
48-
const app = container.getProvider('app').getImmediate();
49-
const authProvider = container.getProvider('auth-internal');
47+
const app = container.getProvider('app-compat').getImmediate();
48+
const storageExp = container
49+
.getProvider('storage-exp')
50+
.getImmediate({ identifier: url });
5051

5152
// TODO: get StorageService instance from component framework instead
5253
// of creating a new one.
5354
const storageServiceCompat: StorageServiceCompat = new StorageServiceCompat(
5455
app,
55-
new StorageService(
56-
app,
57-
authProvider,
58-
new XhrIoPool(),
59-
url,
60-
firebase.SDK_VERSION
61-
)
56+
storageExp
6257
);
6358
return storageServiceCompat;
6459
}
@@ -69,7 +64,7 @@ export function registerStorage(instance: _FirebaseNamespace): void {
6964
TaskState,
7065
TaskEvent,
7166
StringFormat,
72-
Storage: StorageService,
67+
Storage: StorageServiceCompat,
7368
Reference: ReferenceCompat
7469
};
7570
instance.INTERNAL.registerComponent(

packages/storage/compat/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"module": "../dist/compat/esm5/index.js",
99
"esm2017": "../dist/compat/esm2017/index.js",
1010
"license": "Apache-2.0",
11-
"typings": "../dist/compat/esm5/packages/firestore/compat/index.d.ts"
11+
"typings": "../dist/compat/esm5/compat/index.d.ts"
1212
}
1313

packages/storage/index.ts

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import {
3434

3535
import { name, version } from './package.json';
3636

37+
import './register-module';
38+
3739
/**
3840
* Type constant for Firebase Storage.
3941
*/
@@ -82,35 +84,3 @@ export function registerStorage(instance: _FirebaseNamespace): void {
8284
}
8385

8486
registerStorage(firebase as _FirebaseNamespace);
85-
86-
/**
87-
* Define extension behavior for `registerStorage`
88-
*/
89-
declare module '@firebase/app-types' {
90-
interface FirebaseNamespace {
91-
storage?: {
92-
(app?: FirebaseApp, url?: string): types.FirebaseStorage;
93-
Storage: typeof types.FirebaseStorage;
94-
95-
StringFormat: {
96-
BASE64: types.StringFormat;
97-
BASE64URL: types.StringFormat;
98-
DATA_URL: types.StringFormat;
99-
RAW: types.StringFormat;
100-
};
101-
TaskEvent: {
102-
STATE_CHANGED: types.TaskEvent;
103-
};
104-
TaskState: {
105-
CANCELED: types.TaskState;
106-
ERROR: types.TaskState;
107-
PAUSED: types.TaskState;
108-
RUNNING: types.TaskState;
109-
SUCCESS: types.TaskState;
110-
};
111-
};
112-
}
113-
interface FirebaseApp {
114-
storage?(storageBucket?: string): types.FirebaseStorage;
115-
}
116-
}

packages/storage/register-module.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import * as types from '@firebase/storage-types';
19+
20+
/**
21+
* Define extension behavior for `registerStorage`
22+
*/
23+
declare module '@firebase/app-types' {
24+
interface FirebaseNamespace {
25+
storage?: {
26+
(app?: FirebaseApp, url?: string): types.FirebaseStorage;
27+
Storage: typeof types.FirebaseStorage;
28+
29+
StringFormat: {
30+
BASE64: types.StringFormat;
31+
BASE64URL: types.StringFormat;
32+
DATA_URL: types.StringFormat;
33+
RAW: types.StringFormat;
34+
};
35+
TaskEvent: {
36+
STATE_CHANGED: types.TaskEvent;
37+
};
38+
TaskState: {
39+
CANCELED: types.TaskState;
40+
ERROR: types.TaskState;
41+
PAUSED: types.TaskState;
42+
RUNNING: types.TaskState;
43+
SUCCESS: types.TaskState;
44+
};
45+
};
46+
}
47+
interface FirebaseApp {
48+
storage?(storageBucket?: string): types.FirebaseStorage;
49+
}
50+
}

packages/storage/rollup.config.compat.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ const es5Builds = [
6060
}
6161
],
6262
plugins: es5BuildPlugins,
63-
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
63+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
64+
treeshake: {
65+
moduleSideEffects: false
66+
}
6467
}
6568
];
6669

@@ -96,7 +99,10 @@ const es2017Builds = [
9699
sourcemap: true
97100
},
98101
plugins: es2017BuildPlugins,
99-
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
102+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
103+
treeshake: {
104+
moduleSideEffects: false
105+
}
100106
}
101107
];
102108

0 commit comments

Comments
 (0)