Skip to content

Commit 9d18b45

Browse files
committed
fix: typings & overload
1 parent e99a189 commit 9d18b45

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1502
-1222
lines changed

apps/demo/src/app.ts

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,55 @@
1-
import {Application} from '@nativescript/core';
2-
import {Firebase, FirebaseOptions} from '@nativescript/firebase-core';
3-
import '@nativescript/firebase-messaging';
1+
import { Application } from '@nativescript/core';
2+
import { firebase } from '@nativescript/firebase-core';
43
import '@nativescript/firebase-admob';
4+
import '@nativescript/firebase-analytics';
5+
import '@nativescript/firebase-auth';
6+
import '@nativescript/firebase-crashlytics';
7+
import '@nativescript/firebase-database';
58
import '@nativescript/firebase-dynamic-links';
69
import '@nativescript/firebase-firestore';
710
import '@nativescript/firebase-functions';
11+
import '@nativescript/firebase-in-app-messaging';
12+
import '@nativescript/firebase-installations';
13+
import '@nativescript/firebase-messaging';
14+
import '@nativescript/firebase-performance';
15+
import '@nativescript/firebase-remote-config';
16+
import '@nativescript/firebase-storage';
17+
18+
import { Admob } from '@nativescript/firebase-admob';
819

9-
import {Messaging} from '@nativescript/firebase-messaging';
10-
import {Admob} from '@nativescript/firebase-admob';
11-
import {DynamicLinks} from '@nativescript/firebase-dynamic-links';
20+
firebase().initializeApp();
1221

13-
Firebase.initializeApp(new FirebaseOptions());
1422
Admob.init();
1523

16-
const dynamicLinks = Firebase.dynamicLinks() as DynamicLinks;
24+
const dynamicLinks = firebase().dynamicLinks();
1725

1826
dynamicLinks.onLink((link) => {
19-
console.log('onLink', link);
27+
console.log('onLink', link);
2028
});
2129

22-
const messaging = Firebase.messaging() as Messaging;
30+
const messaging = firebase().messaging();
2331
messaging.onMessage((message) => {
24-
console.log('Firebase onMessage', message);
32+
console.log('Firebase onMessage', message);
2533
});
2634

2735
messaging.onNotificationTap((message) => {
28-
console.log('Firebase onNotificationTap', message);
36+
console.log('Firebase onNotificationTap', message);
2937
});
3038

3139
messaging.onToken((token) => {
32-
console.log('Firebase onToken', token);
40+
console.log('Firebase onToken', token);
3341
});
3442

3543
messaging
36-
.requestPermission()
37-
.then(() => {
38-
console.log('requestPermission', 'done');
39-
messaging.registerDeviceForRemoteMessages().catch((e) => {
40-
console.error('registerDeviceForRemoteMessages', e);
41-
});
42-
})
43-
.catch((e) => {
44-
console.error('requestPermission', e);
45-
});
46-
47-
Application.run({moduleName: 'app-root'});
44+
.requestPermission()
45+
.then(() => {
46+
console.log('requestPermission', 'done');
47+
messaging.registerDeviceForRemoteMessages().catch((e) => {
48+
console.error('registerDeviceForRemoteMessages', e);
49+
});
50+
})
51+
.catch((e) => {
52+
console.error('requestPermission', e);
53+
});
54+
55+
Application.run({ moduleName: 'app-root' });

apps/demo/src/plugin-demos/firebase-admob.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Observable, EventData, Page } from '@nativescript/core';
22
import { DemoSharedFirebaseAdmob } from '@demo/shared';
3-
import { Firebase } from '@nativescript/firebase-core';
3+
import { firebase, Firebase } from '@nativescript/firebase-core';
44
import { AdEventType, InterstitialAd, RewardedInterstitialAd, RewardedAd, BannerAd, BannerAdSize, Admob, AdsConsent, NativeAd, NativeAdLoader, NativeAdView } from '@nativescript/firebase-admob';
55
import { AdChoicesPlacement, NativeAdEventType } from '@nativescript/firebase-admob/nativead/common';
66

@@ -24,7 +24,7 @@ export class DemoModel extends DemoSharedFirebaseAdmob {
2424
//this.interstitial();
2525
//this.rewardedInterstitial();
2626
//this.rewarded();
27-
this.admob = Firebase.admob();
27+
this.admob = firebase().admob();
2828
// ATTrackingManager.requestTrackingAuthorizationWithCompletionHandler((status) => {
2929
// console.log('ATTrackingManager', status);
3030
// });
Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
1-
import { Observable, EventData, Page } from '@nativescript/core';
1+
import { EventData, Page } from '@nativescript/core';
22
import { DemoSharedFirebaseAnalytics } from '@demo/shared';
3-
import { Firebase } from '@nativescript/firebase-core';
3+
import { firebase } from '@nativescript/firebase-core';
44
import '@nativescript/firebase-analytics';
5-
import { Analytics } from '@nativescript/firebase-analytics';
65
export function navigatingTo(args: EventData) {
76
const page = <Page>args.object;
87
page.bindingContext = new DemoModel();
98
}
109

1110
export class DemoModel extends DemoSharedFirebaseAnalytics {
1211
logCartEvent() {
13-
const analytics: Analytics = Firebase.analytics();
14-
analytics.logEvent('add_to_cart', {
15-
items: [
16-
{
17-
item_brand: 'ITEM_BRAND_1',
18-
item_category: 'IMTEM_CATEGORY_1',
19-
item_name: 'ITEM_NAME_1',
20-
item_price: 300,
21-
},
22-
{
23-
item_brand: 'ITEM_BRAND_2',
24-
item_category: 'IMTEM_CATEGORY_2',
25-
item_name: 'ITEM_NAME_2',
26-
item_price: 400,
27-
},
28-
{
29-
item_brand: 'ITEM_BRAND_3',
30-
item_category: 'ITEM_CATEGORY_3',
31-
item_name: 'ITEM_NAME',
32-
item_price: 500,
33-
},
34-
{
35-
item_brand: 'ITEM_BRAND_4',
36-
item_category: 'ITEM_CATEGORY_4',
37-
item_name: 'ITEM_NAME_4',
38-
item_price: 600,
39-
},
40-
]
41-
});
12+
firebase()
13+
.analytics()
14+
.logEvent('add_to_cart', {
15+
items: [
16+
{
17+
item_brand: 'ITEM_BRAND_1',
18+
item_category: 'IMTEM_CATEGORY_1',
19+
item_name: 'ITEM_NAME_1',
20+
item_price: 300,
21+
},
22+
{
23+
item_brand: 'ITEM_BRAND_2',
24+
item_category: 'IMTEM_CATEGORY_2',
25+
item_name: 'ITEM_NAME_2',
26+
item_price: 400,
27+
},
28+
{
29+
item_brand: 'ITEM_BRAND_3',
30+
item_category: 'ITEM_CATEGORY_3',
31+
item_name: 'ITEM_NAME',
32+
item_price: 500,
33+
},
34+
{
35+
item_brand: 'ITEM_BRAND_4',
36+
item_category: 'ITEM_CATEGORY_4',
37+
item_name: 'ITEM_NAME_4',
38+
item_price: 600,
39+
},
40+
],
41+
});
4242
}
4343
}
Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Observable, EventData, Page, fromObject } from '@nativescript/core';
22
import { DemoSharedFirebaseAuth } from '@demo/shared';
3-
import { Firebase } from '@nativescript/firebase-core';
3+
import { firebase, Firebase } from '@nativescript/firebase-core';
44
import '@nativescript/firebase-auth';
55
import { Auth, User } from '@nativescript/firebase-auth';
66
export function navigatingTo(args: EventData) {
@@ -12,24 +12,29 @@ export class DemoModel extends DemoSharedFirebaseAuth {
1212
email: string;
1313
password: string;
1414
user: User;
15-
constructor(){
15+
constructor() {
1616
super();
17-
Firebase.auth().addAuthStateChangeListener((user)=>{
18-
this._setCurrentUser(user);
19-
});
17+
firebase()
18+
.auth()
19+
.addAuthStateChangeListener((user) => {
20+
this._setCurrentUser(user);
21+
});
2022
}
2123
createUser() {
22-
const auth: Auth = Firebase.auth();
23-
auth.createUserWithEmailAndPassword(this.email, this.password).then((user) => {
24-
this.set('user', user);
25-
}).catch(e =>{
26-
console.error('createUser', e);
27-
});
24+
firebase()
25+
.auth()
26+
.createUserWithEmailAndPassword(this.email, this.password)
27+
.then((user) => {
28+
this.set('user', user);
29+
})
30+
.catch((e) => {
31+
console.error('createUser', e);
32+
});
2833
}
2934

3035
loginUser() {
31-
const auth: Auth = Firebase.auth();
32-
auth
36+
firebase()
37+
.auth()
3338
.signInWithEmailAndPassword(this.email, this.password)
3439
.then((value) => {
3540
console.log('loginUser', value);
@@ -40,22 +45,21 @@ export class DemoModel extends DemoSharedFirebaseAuth {
4045
});
4146
}
4247

43-
_setCurrentUser(user: User){
48+
_setCurrentUser(user: User) {
4449
this.set('user', user);
4550
this.set('uid', user?.uid);
4651
this.set('displayName', user?.displayName);
4752
this.set('displayEmail', user?.email);
4853
this.set('photoURL', user?.photoURL);
4954
}
5055

51-
getCurrentUser(){
52-
const auth: Auth = Firebase.auth();
53-
this._setCurrentUser(auth?.user)
56+
getCurrentUser() {
57+
const auth = firebase().auth();
58+
this._setCurrentUser(auth?.user);
5459
}
5560

56-
logOutUser(){
57-
const auth: Auth = Firebase.auth();
58-
auth.signOut();
61+
logOutUser() {
62+
firebase().auth().signOut();
5963
this._setCurrentUser(undefined);
6064
}
6165
}

apps/demo/src/plugin-demos/firebase-crashlytics.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Observable, EventData, Page } from '@nativescript/core';
22
import { DemoSharedFirebaseCrashlytics } from '@demo/shared';
3-
import { Firebase } from '@nativescript/firebase-core';
3+
import { firebase } from '@nativescript/firebase-core';
44
import '@nativescript/firebase-crashlytics';
55
import { Crashlytics } from '@nativescript/firebase-crashlytics';
66

@@ -13,7 +13,7 @@ export class DemoModel extends DemoSharedFirebaseCrashlytics {
1313
crashlytics: Crashlytics;
1414
constructor() {
1515
super();
16-
this.crashlytics = Firebase.crashlytics();
16+
this.crashlytics = firebase().crashlytics();
1717
this.crashlytics.setCrashlyticsCollectionEnabled(true);
1818
//this.crash();
1919
this.logError();

apps/demo/src/plugin-demos/firebase-database.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Observable, EventData, Page } from '@nativescript/core';
22
import { DemoSharedFirebaseDatabase } from '@demo/shared';
3-
import { Firebase } from '@nativescript/firebase-core';
3+
import { firebase } from '@nativescript/firebase-core';
44
import { Database } from '@nativescript/firebase-database';
55
import { Auth } from '@nativescript/firebase-auth';
66
export function navigatingTo(args: EventData) {
@@ -13,16 +13,16 @@ export class DemoModel extends DemoSharedFirebaseDatabase {
1313
auth: Auth;
1414
constructor() {
1515
super();
16-
this.auth = Firebase.auth();
17-
this.database = Firebase.database();
16+
this.auth = firebase().auth();
17+
this.database = firebase().database();
1818
this.transaction();
1919
this.randomData();
2020
this.children();
2121
}
2222
randomData() {
23-
this.database
23+
this.database
2424
.ref('/random')
25-
.push({ name: 'random' , float: 1.1 })
25+
.push({ name: 'random', float: 1.1 })
2626
.then((value) => {
2727
console.log('push randomData', value);
2828
});
Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,45 @@
1-
import {Observable, EventData, Page} from '@nativescript/core';
2-
import {DemoSharedFirebaseFirestore} from '@demo/shared';
3-
import {Firestore, GeoPoint} from '@nativescript/firebase-firestore';
4-
import {Firebase} from "@nativescript/firebase-core";
1+
import { Observable, EventData, Page } from '@nativescript/core';
2+
import { DemoSharedFirebaseFirestore } from '@demo/shared';
3+
import { Firestore, GeoPoint } from '@nativescript/firebase-firestore';
4+
import { firebase } from '@nativescript/firebase-core';
55

66
export function navigatingTo(args: EventData) {
7-
const page = <Page>args.object;
8-
page.bindingContext = new DemoModel();
7+
const page = <Page>args.object;
8+
page.bindingContext = new DemoModel();
99
}
1010

1111
export class DemoModel extends DemoSharedFirebaseFirestore {
12-
firestore: Firestore;
12+
firestore: Firestore;
1313

14-
constructor() {
15-
super();
16-
this.firestore = Firebase.firestore();
17-
this.firestore.collection('users')
18-
.add({
19-
first: "Ada",
20-
last: "Lovelace",
21-
born: 1815
22-
}).then((docRef) => {
23-
console.log("Document written with ID: ", docRef.id);
24-
})
25-
.catch((error) => {
26-
console.error("Error adding document: ", error);
27-
});
14+
constructor() {
15+
super();
16+
this.firestore = firebase().firestore();
17+
this.firestore
18+
.collection('users')
19+
.add({
20+
first: 'Ada',
21+
last: 'Lovelace',
22+
born: 1815,
23+
})
24+
.then((docRef) => {
25+
console.log('Document written with ID: ', docRef.id);
26+
})
27+
.catch((error) => {
28+
console.error('Error adding document: ', error);
29+
});
2830

29-
const geo = new GeoPoint(10, -10);
30-
this.firestore.collection('geo')
31-
.add({
32-
thing: 'it',
33-
geo
34-
}).then((docRef) => {
35-
console.log("Geo Document written with ID: ", docRef.id);
36-
})
37-
.catch((error) => {
38-
console.error("Error adding geo document: ", error);
39-
});
40-
}
31+
const geo = new GeoPoint(10, -10);
32+
this.firestore
33+
.collection('geo')
34+
.add({
35+
thing: 'it',
36+
geo,
37+
})
38+
.then((docRef) => {
39+
console.log('Geo Document written with ID: ', docRef.id);
40+
})
41+
.catch((error) => {
42+
console.error('Error adding geo document: ', error);
43+
});
44+
}
4145
}

apps/demo/src/plugin-demos/firebase-messaging.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Observable, EventData, Page } from '@nativescript/core';
22
import { DemoSharedFirebaseMessaging } from '@demo/shared';
3-
import { Firebase } from '@nativescript/firebase-core';
4-
import { Messaging } from '@nativescript/firebase-messaging';
3+
import { firebase } from '@nativescript/firebase-core';
54

65
export function navigatingTo(args: EventData) {
76
const page = <Page>args.object;
@@ -11,7 +10,7 @@ export function navigatingTo(args: EventData) {
1110
export class DemoModel extends DemoSharedFirebaseMessaging {
1211
constructor(){
1312
super();
14-
(<Messaging>Firebase.messaging()).getToken().then(token =>{
13+
firebase().messaging().getToken().then(token =>{
1514
console.log('getToken', token);
1615
}).catch(e =>{
1716
console.log('getToken', e);

0 commit comments

Comments
 (0)