本文整理匯總了TypeScript中@angular/fire/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);
//.........這裏部分代碼省略.........
示例2: expect
(list: any) => {
if (prev) {
expect(list[0]).toBe(prev[0]);
done();
} else {
prev = list;
questionsSnapshotted.push({ name: 'bob' });
}
},
示例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));
});
示例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');
})
示例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' });
});