当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript database-deprecated.FirebaseListObservable类代码示例

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