File tree 5 files changed +72
-0
lines changed
5 files changed +72
-0
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @firebase/util " : patch
3
+ ---
4
+
5
+ Added a utility function and type for compat interop API
Original file line number Diff line number Diff line change @@ -37,3 +37,4 @@ export * from './src/validation';
37
37
export * from './src/utf8' ;
38
38
export * from './src/exponential_backoff' ;
39
39
export * from './src/formatters' ;
40
+ export * from './src/compat' ;
Original file line number Diff line number Diff line change @@ -32,3 +32,4 @@ export * from './src/validation';
32
32
export * from './src/utf8' ;
33
33
export * from './src/exponential_backoff' ;
34
34
export * from './src/formatters' ;
35
+ export * from './src/compat' ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @license
3
+ * Copyright 2021 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
+ export interface Compat < T > {
19
+ _delegate : T ;
20
+ }
21
+
22
+ export function getModularInstance < ExpService > (
23
+ service : Compat < ExpService > | ExpService
24
+ ) : ExpService {
25
+ if ( service && ( service as Compat < ExpService > ) . _delegate ) {
26
+ return ( service as Compat < ExpService > ) . _delegate ;
27
+ } else {
28
+ return service as ExpService ;
29
+ }
30
+ }
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @license
3
+ * Copyright 2021 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 { expect } from 'chai' ;
19
+ import { getModularInstance } from '../src/compat' ;
20
+
21
+ describe ( 'getModularInstance()' , ( ) => {
22
+ it ( 'returns _delegate from a compat object' , ( ) => {
23
+ const compat = {
24
+ _delegate : { }
25
+ } ;
26
+ const modularThing = getModularInstance ( compat ) ;
27
+ expect ( modularThing ) . to . eq ( compat . _delegate ) ;
28
+ } ) ;
29
+
30
+ it ( 'returns the object itself if it is not a compat object' , ( ) => {
31
+ const thing = { } ;
32
+ const modularThing = getModularInstance ( thing ) ;
33
+ expect ( modularThing ) . to . eq ( thing ) ;
34
+ } ) ;
35
+ } ) ;
You can’t perform that action at this time.
0 commit comments