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

TypeScript database-deprecated.FirebaseListObservable类代码示例

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

本文整理汇总了TypeScript中angularfire2/database-deprecated.FirebaseListObservable的典型用法代码示例。如果您正苦于以下问题:TypeScript FirebaseListObservable类的具体用法?TypeScript FirebaseListObservable怎么用?TypeScript FirebaseListObservable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了FirebaseListObservable类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: describe

  describe('methods', () => {

    let toKey: any;
    let val1: any;
    let val2: any;
    let val3: any;
    let questions: FirebaseListObservable<any>;
    let questionsSnapshotted: FirebaseListObservable<any>;
    let ref: any;
    let refSnapshotted: any;
    let subscription: Subscription;

    beforeEach((done: any) => {
      toKey = (val: any) => val.key;
      val1 = { key: 'key1' };
      val2 = { key: 'key2' };
      val3 = { key: 'key3' };
      app.database().ref().remove(done);
      questions = FirebaseListFactory(app.database().ref(`questions`));
      questionsSnapshotted = FirebaseListFactory(app.database().ref(`questionssnapshot`), { preserveSnapshot: true });
      ref = questions.$ref;
      refSnapshotted = questionsSnapshotted.$ref;
    });


    afterEach((done: any) => {
      if (subscription && !subscription.closed) {
        subscription.unsubscribe();
      }
      Promise.all([ref.remove(), refSnapshotted.remove()]).then(done, done.fail);
    });


    it('should emit only when the initial data set has been loaded', (done: any) => {
      questions.$ref.ref.set([{ initial1: true }, { initial2: true }, { initial3: true }, { initial4: true }])
        .then(() => toPromise.call(skipAndTake(questions, 1)))
        .then((val: any[]) => {
          expect(val.length).toBe(4);
        })
        .then(() => {
          done();
        }, done.fail);
    });


    it('should be resistant to non-asynchronous child_added quirks', (done: any) => {

      // If push is called (or set or update, too, I guess) immediately after
      // an on or once listener is added, it appears that the on or once
      // child_added listeners are invoked immediately - i.e. not
      // asynchronously - and the list implementation needs to support that.

      questions.$ref.ref.push({ number: 1 })
        .then(() => {
          let calls: string[] = [];
          questions.$ref.ref.once('child_added', (snap) => calls.push('child_added:' + snap.val().number));
          skipAndTake(questions).subscribe(
            (list: any) => {
              expect(calls).toEqual(['child_added:2', 'pushed']);
              expect(list.map((i: any) => i.number)).toEqual([1, 2]);
              done();
            },
            done.fail
          );
          questions.push({ number: 2 });
          calls.push('pushed');
        })
        .catch(done.fail);
    });


    it('should emit a new value when a child moves', (done: any) => {
     let question = skipAndTake(questions, 1, 2)
     subscription = _do.call(question, (data: any) => {
        expect(data.length).toBe(2);
        expect(data[0].push2).toBe(true);
        expect(data[1].push1).toBe(true);
      })
      .subscribe(() => {
        done();
      }, done.fail);

      let child1 = ref.push({ push1: true }, () => {
        ref.push({ push2: true }, () => {
          child1.setPriority('ZZZZ')
        });
      });
    });


    it('should emit unwrapped data by default', (done: any) => {
      ref.remove(() => {
        ref.push({ unwrapped: true }, () => {
          subscription = _do.call(skipAndTake(questions, 1), (data: any) => {
            expect(data.length).toBe(1);
            expect(data[0].unwrapped).toBe(true);
          })
          .subscribe(() => {
            done();
          }, done.fail);
//.........这里部分代码省略.........
开发者ID:Tetsumote,项目名称:angularfire2,代码行数:101,代码来源:firebase_list_factory.spec.ts


示例2: expect

 (list: any) => {
   if (prev) {
     expect(list[0]).toBe(prev[0]);
     done();
   } else {
     prev = list;
     questionsSnapshotted.push({ name: 'bob' });
   }
 },
开发者ID:Tetsumote,项目名称:angularfire2,代码行数:9,代码来源:firebase_list_factory.spec.ts


示例3: afterEach

 afterEach((done: any) => {
   subscription = questions
     .skip(2)
     .take(1)
     .subscribe((items: any[]) => {
       expect(items.length).toBe(3);
       done();
     }, done.fail);
   questions.$ref.ref.set(initialData)
     .then(() => ref.child(keyToRemove).remove())
     .then(() => ref.child(keyToRemove).set(true));
 });
开发者ID:Tetsumote,项目名称:angularfire2,代码行数:12,代码来源:firebase_list_factory.spec.ts


示例4: skipAndTake

 .then(() => {
   let calls: string[] = [];
   questions.$ref.ref.once('child_added', (snap) => calls.push('child_added:' + snap.val().number));
   skipAndTake(questions).subscribe(
     (list: any) => {
       expect(calls).toEqual(['child_added:2', 'pushed']);
       expect(list.map((i: any) => i.number)).toEqual([1, 2]);
       done();
     },
     done.fail
   );
   questions.push({ number: 2 });
   calls.push('pushed');
 })
开发者ID:Tetsumote,项目名称:angularfire2,代码行数:14,代码来源:firebase_list_factory.spec.ts


示例5: it

    it('should re-emit identical instances of unchanged children as snapshots', (done: any) => {

      let prev: any;

      take.call(questionsSnapshotted, 2).subscribe(
        (list: any) => {
          if (prev) {
            expect(list[0]).toBe(prev[0]);
            done();
          } else {
            prev = list;
            questionsSnapshotted.push({ name: 'bob' });
          }
        },
        done.fail
      );
      questionsSnapshotted.push({ name: 'alice' });
    });
开发者ID:Tetsumote,项目名称:angularfire2,代码行数:18,代码来源:firebase_list_factory.spec.ts



注:本文中的angularfire2/database-deprecated.FirebaseListObservable类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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