• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript fire.FirebaseApp类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript database.fromRef函数代码示例发布时间:2022-05-28
下一篇:
TypeScript fire.AngularFireModule类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap