Skip to content

Commit 2d8ac14

Browse files
exaby73mikehardy
authored andcommitted
feat(ml): add modular API
1 parent 305d38b commit 2d8ac14

File tree

6 files changed

+66
-9
lines changed

6 files changed

+66
-9
lines changed

packages/ml/e2e/ml.e2e.js

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,35 @@
1616
*/
1717

1818
describe('ml()', function () {
19-
describe('namespace', function () {
20-
it('accessible from firebase.app()', function () {
21-
const app = firebase.app();
22-
should.exist(app.ml);
23-
app.ml().app.should.equal(app);
19+
describe('v8 compatibility', function () {
20+
describe('namespace', function () {
21+
it('accessible from firebase.app()', function () {
22+
const app = firebase.app();
23+
should.exist(app.ml);
24+
app.ml().app.should.equal(app);
25+
});
26+
27+
it('supports multiple apps', async function () {
28+
firebase.ml().app.name.should.equal('[DEFAULT]');
29+
30+
firebase
31+
.ml(firebase.app('secondaryFromNative'))
32+
.app.name.should.equal('secondaryFromNative');
33+
34+
firebase.app('secondaryFromNative').ml().app.name.should.equal('secondaryFromNative');
35+
});
2436
});
37+
});
2538

26-
it('supports multiple apps', async function () {
27-
firebase.ml().app.name.should.equal('[DEFAULT]');
39+
describe('modular', function () {
40+
it('supports multiple apps', function () {
41+
const { getML } = mlModular;
42+
const ml = getML();
43+
const secondaryML = getML(firebase.app('secondaryFromNative'));
2844

29-
firebase.ml(firebase.app('secondaryFromNative')).app.name.should.equal('secondaryFromNative');
45+
ml.app.name.should.equal('[DEFAULT]');
3046

31-
firebase.app('secondaryFromNative').ml().app.name.should.equal('secondaryFromNative');
47+
secondaryML.app.name.should.equal('secondaryFromNative');
3248
});
3349
});
3450
});

packages/ml/lib/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class FirebaseMLModule extends FirebaseModule {}
3333
// import { SDK_VERSION } from '@react-native-firebase/ml';
3434
export const SDK_VERSION = version;
3535

36+
export * from './modular';
37+
3638
// import ML from '@react-native-firebase/ml';
3739
// ml().X(...);
3840
export default createModuleNamespace({

packages/ml/lib/modular/index.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { ReactNativeFirebase } from '@react-native-firebase/app';
2+
import { FirebaseMLTypes } from '..';
3+
4+
type FirebaseApp = ReactNativeFirebase.Module;
5+
type FirebaseML = FirebaseMLTypes.Module;
6+
7+
/**
8+
* Returns the existing default {@link FirebaseML} instance that is associated with the
9+
* default {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new
10+
* instance with default settings.
11+
*
12+
* @returns The {@link FirebaseML} instance of the provided app.
13+
*/
14+
export declare function getML(app?: FirebaseApp): FirebaseML;

packages/ml/lib/modular/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { firebase } from '..';
2+
3+
/**
4+
* @typedef {import('@react-native-firebase/app').ReactNativeFirebase.Module} FirebaseApp
5+
* @typedef {import('..').FirebaseMLTypes.Module} FirebaseML
6+
*/
7+
8+
/**
9+
* @param {FirebaseApp | undefined} app
10+
* @returns {FirebaseML}
11+
*/
12+
export function getML(app) {
13+
if (app) {
14+
return firebase.ml(app);
15+
}
16+
return firebase.ml();
17+
}

tests/app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import * as inAppMessagingModular from '@react-native-firebase/in-app-messaging'
5151
import * as installationsModular from '@react-native-firebase/installations';
5252
import * as crashlyticsModular from '@react-native-firebase/crashlytics';
5353
import * as dynamicLinksModular from '@react-native-firebase/dynamic-links';
54+
import * as mlModular from '@react-native-firebase/ml';
5455

5556
jet.exposeContextProperty('NativeModules', NativeModules);
5657
jet.exposeContextProperty('NativeEventEmitter', NativeEventEmitter);
@@ -72,6 +73,7 @@ jet.exposeContextProperty('crashlyticsModular', crashlyticsModular);
7273
jet.exposeContextProperty('dynamicLinksModular', dynamicLinksModular);
7374
jet.exposeContextProperty('databaseModular', databaseModular);
7475
jet.exposeContextProperty('firestoreModular', firestoreModular);
76+
jet.exposeContextProperty('mlModular', mlModular);
7577

7678
firebase.database().useEmulator('localhost', 9000);
7779
firebase.auth().useEmulator('http://localhost:9099');

tests/e2e/globals.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,10 @@ Object.defineProperty(global, 'firestoreModular', {
161161
},
162162
});
163163

164+
Object.defineProperty(global, 'mlModular', {
165+
get() {
166+
return jet.mlModular;
167+
},
168+
});
169+
164170
global.isCI = !!process.env.CI;

0 commit comments

Comments
 (0)