當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript fire.FirebaseApp類代碼示例

本文整理匯總了TypeScript中@angular/fire.FirebaseApp的典型用法代碼示例。如果您正苦於以下問題:TypeScript FirebaseApp類的具體用法?TypeScript FirebaseApp怎麽用?TypeScript FirebaseApp使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了FirebaseApp類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: describe

describe('AngularFireDatabase', () => {
  let app: FirebaseApp;
  let db: AngularFireDatabase;
  let zone: NgZone

  beforeEach(() => {
    TestBed.configureTestingModule({
      imports: [
        AngularFireModule.initializeApp(COMMON_CONFIG, FIREBASE_APP_NAME),
        AngularFireDatabaseModule
      ]
    });
    inject([FirebaseApp, AngularFireDatabase, NgZone], (app_: FirebaseApp, _db: AngularFireDatabase, _zone: NgZone) => {
      app = app_;
      db = _db;
      zone = _zone;
    })();
  });

  afterEach(done => {
    app.delete().then(done, done.fail);
  });

  describe('<constructor>', () => {

    it('should be an AngularFireDatabase type', () => {
      expect(db instanceof AngularFireDatabase).toEqual(true);
    });

    it('should have an initialized Firebase app', () => {
      expect(db.database.app).toBeDefined();
      expect(db.database.app).toEqual(app);
    });

    it('should accept a Firebase App in the constructor', () => {
      const __db = new AngularFireDatabase(app.options, app.name, undefined!, {}, zone);
      expect(__db instanceof AngularFireDatabase).toEqual(true);
    });

    it('should have an initialized Firebase app instance member', () => {
      expect(db.database.app.name).toEqual(FIREBASE_APP_NAME);
    });

  });

});
開發者ID:PaulD11,項目名稱:angularfire2,代碼行數:46,代碼來源:database.spec.ts

示例2: describe

describe('AngularFirestore with different app', () => {
  let app: FirebaseApp;
  let afs: AngularFirestore;

  beforeEach(() => {
    TestBed.configureTestingModule({
      imports: [
        AngularFireModule.initializeApp(COMMON_CONFIG),
        AngularFirestoreModule
      ],
      providers: [
        { provide: FirebaseNameOrConfigToken, useValue: FIREBASE_APP_NAME_TOO },
        { provide: FirebaseOptionsToken, useValue: COMMON_CONFIG }
      ]
    });
    inject([FirebaseApp, AngularFirestore], (app_: FirebaseApp, _afs: AngularFirestore) => {
      app = app_;
      afs = _afs;
    })();
  });

  afterEach(done => {
    app.delete().then(done, done.fail);
  });

  describe('<constructor>', () => {

    it('should be an AngularFirestore type', () => {
      expect(afs instanceof AngularFirestore).toEqual(true);
    });

    it('should have an initialized Firebase app', () => {
      expect(afs.firestore.app).toBeDefined();
      expect(afs.firestore.app).toEqual(app);
    });

    it('should have an initialized Firebase app instance member', () => {
      expect(afs.firestore.app.name).toEqual(FIREBASE_APP_NAME_TOO);
    });
  });

});
開發者ID:PaulD11,項目名稱:angularfire2,代碼行數:42,代碼來源:firestore.spec.ts

示例3: describe

describe('AngularFireFunctions with different app', () => {
  let app: FirebaseApp;
  let afFns: AngularFireFunctions;

  beforeEach(() => {
    TestBed.configureTestingModule({
      imports: [
        AngularFireModule.initializeApp(COMMON_CONFIG),
        AngularFireFunctionsModule
      ],
      providers: [
        { provide: FirebaseNameOrConfigToken, useValue: FIREBASE_APP_NAME_TOO },
        { provide: FirebaseOptionsToken, useValue: COMMON_CONFIG },
        { provide: FunctionsRegionToken, useValue: 'asia-northeast1' },
      ]
    });
    inject([FirebaseApp, AngularFireFunctions], (app_: FirebaseApp, _fns: AngularFireFunctions) => {
      app = app_;
      afFns = _fns;
    })();
  });

  afterEach(done => {
    app.delete();
    done();
  });

  describe('<constructor>', () => {

    it('should be an AngularFireAuth type', () => {
      expect(afFns instanceof AngularFireFunctions).toEqual(true);
    });

    it('should have the Firebase Functions instance', () => {
      expect(afFns.functions).toBeDefined();
    });

  });

});
開發者ID:PaulD11,項目名稱:angularfire2,代碼行數:40,代碼來源:functions.spec.ts

示例4: inject

 inject([FirebaseApp, AngularFireDatabase], (app_: FirebaseApp, _db: AngularFireDatabase) => {
   app = app_;
   db = _db;
   app.database().goOffline();
   createRef = (path: string) => { app.database().goOffline(); return app.database().ref(path); };
 })();
開發者ID:PaulD11,項目名稱:angularfire2,代碼行數:6,代碼來源:state-changes.spec.ts

示例5: describe

describe('AngularFirestoreCollection', () => {
  let app: FirebaseApp;
  let afs: AngularFirestore;
  let sub: Subscription;

  beforeEach(() => {
    TestBed.configureTestingModule({
      imports: [
        AngularFireModule.initializeApp(COMMON_CONFIG),
        AngularFirestoreModule.enablePersistence()
      ]
    });
    inject([FirebaseApp, AngularFirestore], (_app: FirebaseApp, _afs: AngularFirestore) => {
      app = _app;
      afs = _afs;
    })();
  });

  afterEach(async (done) => {
    await app.delete();
    done();
  });

  describe('valueChanges()', () => {

    it('should get unwrapped snapshot', async (done: any) => {
      const ITEMS = 4;
      const { randomCollectionName, ref, stocks, names } = await collectionHarness(afs, ITEMS);

      const sub = stocks.valueChanges().subscribe(data => {
        // unsub immediately as we will be deleting data at the bottom
        // and that will trigger another subscribe callback and fail
        // the test
        sub.unsubscribe();
        // We added four things. This should be four.
        // This could not be four if the batch failed or
        // if the collection state is altered during a test run
        expect(data.length).toEqual(ITEMS);
        data.forEach(stock => {
          // We used the same piece of data so they should all equal
          expect(stock).toEqual(FAKE_STOCK_DATA);
        });
        // Delete them all
        const promises = names.map(name => ref.doc(name).delete());
        Promise.all(promises).then(done).catch(fail);
      });

    });

    it('should handle multiple subscriptions (hot)', async (done: any) => {
      const ITEMS = 4;
      const { randomCollectionName, ref, stocks, names } = await collectionHarness(afs, ITEMS);
      const changes = stocks.valueChanges();
      const sub = changes.subscribe(() => {}).add(
        changes.pipe(take(1)).subscribe(data => {
          expect(data.length).toEqual(ITEMS);
          sub.unsubscribe();
        })
      ).add(() => {
        deleteThemAll(names, ref).then(done).catch(done.fail);
      });
    });

    it('should handle multiple subscriptions (warm)', async (done: any) => {
      const ITEMS = 4;
      const { randomCollectionName, ref, stocks, names } = await collectionHarness(afs, ITEMS);
      const changes = stocks.valueChanges();
      changes.pipe(take(1)).subscribe(() => {}).add(() => {
        const sub = changes.pipe(take(1)).subscribe(data => {
          expect(data.length).toEqual(ITEMS);
        }).add(() => {
          deleteThemAll(names, ref).then(done).catch(done.fail);
        });
      });
    });

    it('should handle dynamic queries that return empty sets', async (done) => {
      const ITEMS = 10;
      let count = 0;
      let firstIndex = 0;
      let pricefilter$ = new BehaviorSubject<number|null>(null);
      const randomCollectionName = randomName(afs.firestore);
      const ref = afs.firestore.collection(`${randomCollectionName}`);
      let names = await createRandomStocks(afs.firestore, ref, ITEMS);
      const sub = pricefilter$.pipe(switchMap(price => {
        return afs.collection(randomCollectionName, ref => price ? ref.where('price', '==', price) : ref).valueChanges()
      })).subscribe(data => {
        count = count + 1;
        // the first time should all be 'added'
        if(count === 1) {
          expect(data.length).toEqual(ITEMS);
          pricefilter$.next(-1);
        }
        // on the second round, we should have filtered out everything
        if(count === 2) {
          expect(data.length).toEqual(0);
          sub.unsubscribe();
          deleteThemAll(names, ref).then(done).catch(done.fail);
        }
      });
//.........這裏部分代碼省略.........
開發者ID:PaulD11,項目名稱:angularfire2,代碼行數:101,代碼來源:collection.spec.ts

示例6: FirebaseListFactory

        .then(() => {

          let query1 = FirebaseListFactory(app.database().ref(`questions`), {
            query: {
              orderByChild: 'data',
              equalTo: { value: 0 }
            }
          });
          let promise1 = toPromise.call(take.call(query1, 1));

          let query2 = FirebaseListFactory(app.database().ref(`questions`), {
            query: {
              orderByChild: 'data',
              equalTo: { value: 0, key: 'val2' }
            }
          });
          let promise2 = toPromise.call(take.call(query2, 1));

          Promise.all([promise1, promise2]).then(([list1, list2]) => {
            expect(list1.map((i: any) => i.$key)).toEqual(['val1', 'val2', 'val3']);
            expect(list2.map((i: any) => i.$key)).toEqual(['val2']);
            done();
          });
        })
開發者ID:PaulD11,項目名稱:angularfire2,代碼行數:24,代碼來源:firebase_list_factory.spec.ts

示例7: it

 it('should listen to only child_added, child_changed events', (done) => {
   const { snapChanges, ref } = prepareSnapshotChanges({
     events: ['child_added', 'child_changed'],
     skipnumber: 1
   });
   const name = 'ligatures';
   snapChanges.pipe(take(1)).subscribe(actions => {
     const data = actions.map(a => a.payload!.val());;
     const copy = [...items];
     copy[0].name = name;
     expect(data).toEqual(copy);
   }).add(done);
   app.database().goOnline();
   ref.set(batch).then(() => {
     ref.child(items[0].key).update({ name })
   });
 });
開發者ID:PaulD11,項目名稱:angularfire2,代碼行數:17,代碼來源:snapshot-changes.spec.ts

示例8:

 createRef = (path: string) => { app.database().goOffline(); return app.database().ref(path); };
開發者ID:PaulD11,項目名稱:angularfire2,代碼行數:1,代碼來源:state-changes.spec.ts

示例9: afterEach

 afterEach(async (done) => {
   await app.delete();
   done();
 });
開發者ID:PaulD11,項目名稱:angularfire2,代碼行數:4,代碼來源:collection.spec.ts


注:本文中的@angular/fire.FirebaseApp類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。