Skip to content

Commit

Permalink
feat(ml): add modular API
Browse files Browse the repository at this point in the history
  • Loading branch information
exaby73 authored and mikehardy committed Oct 10, 2023
1 parent 3dca3c1 commit 0859705
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 9 deletions.
34 changes: 25 additions & 9 deletions packages/ml/e2e/ml.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,35 @@
*/

describe('ml()', function () {
describe('namespace', function () {
it('accessible from firebase.app()', function () {
const app = firebase.app();
should.exist(app.ml);
app.ml().app.should.equal(app);
describe('v8 compatibility', function () {
describe('namespace', function () {
it('accessible from firebase.app()', function () {
const app = firebase.app();
should.exist(app.ml);
app.ml().app.should.equal(app);
});

it('supports multiple apps', async function () {
firebase.ml().app.name.should.equal('[DEFAULT]');

firebase
.ml(firebase.app('secondaryFromNative'))
.app.name.should.equal('secondaryFromNative');

firebase.app('secondaryFromNative').ml().app.name.should.equal('secondaryFromNative');
});
});
});

it('supports multiple apps', async function () {
firebase.ml().app.name.should.equal('[DEFAULT]');
describe('modular', function () {
it('supports multiple apps', function () {
const { getML } = mlModular;
const ml = getML();
const secondaryML = getML(firebase.app('secondaryFromNative'));

firebase.ml(firebase.app('secondaryFromNative')).app.name.should.equal('secondaryFromNative');
ml.app.name.should.equal('[DEFAULT]');

firebase.app('secondaryFromNative').ml().app.name.should.equal('secondaryFromNative');
secondaryML.app.name.should.equal('secondaryFromNative');
});
});
});
2 changes: 2 additions & 0 deletions packages/ml/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class FirebaseMLModule extends FirebaseModule {}
// import { SDK_VERSION } from '@react-native-firebase/ml';
export const SDK_VERSION = version;

export * from './modular';

// import ML from '@react-native-firebase/ml';
// ml().X(...);
export default createModuleNamespace({
Expand Down
14 changes: 14 additions & 0 deletions packages/ml/lib/modular/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ReactNativeFirebase } from '@react-native-firebase/app';
import { FirebaseMLTypes } from '..';

type FirebaseApp = ReactNativeFirebase.Module;
type FirebaseML = FirebaseMLTypes.Module;

/**
* Returns the existing default {@link FirebaseML} instance that is associated with the
* default {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new
* instance with default settings.
*
* @returns The {@link FirebaseML} instance of the provided app.
*/
export declare function getML(app?: FirebaseApp): FirebaseML;
17 changes: 17 additions & 0 deletions packages/ml/lib/modular/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { firebase } from '..';

/**
* @typedef {import('@react-native-firebase/app').ReactNativeFirebase.Module} FirebaseApp
* @typedef {import('..').FirebaseMLTypes.Module} FirebaseML
*/

/**
* @param {FirebaseApp | undefined} app
* @returns {FirebaseML}
*/
export function getML(app) {
if (app) {
return firebase.ml(app);
}
return firebase.ml();
}
2 changes: 2 additions & 0 deletions tests/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import * as inAppMessagingModular from '@react-native-firebase/in-app-messaging'
import * as installationsModular from '@react-native-firebase/installations';
import * as crashlyticsModular from '@react-native-firebase/crashlytics';
import * as dynamicLinksModular from '@react-native-firebase/dynamic-links';
import * as mlModular from '@react-native-firebase/ml';

jet.exposeContextProperty('NativeModules', NativeModules);
jet.exposeContextProperty('NativeEventEmitter', NativeEventEmitter);
Expand All @@ -72,6 +73,7 @@ jet.exposeContextProperty('crashlyticsModular', crashlyticsModular);
jet.exposeContextProperty('dynamicLinksModular', dynamicLinksModular);
jet.exposeContextProperty('databaseModular', databaseModular);
jet.exposeContextProperty('firestoreModular', firestoreModular);
jet.exposeContextProperty('mlModular', mlModular);

firebase.database().useEmulator('localhost', 9000);
firebase.auth().useEmulator('http://localhost:9099');
Expand Down
6 changes: 6 additions & 0 deletions tests/e2e/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,10 @@ Object.defineProperty(global, 'firestoreModular', {
},
});

Object.defineProperty(global, 'mlModular', {
get() {
return jet.mlModular;
},
});

global.isCI = !!process.env.CI;

0 comments on commit 0859705

Please sign in to comment.