관찰 대상을 query
에 사용하면 옵션이 제대로 작동하지 않습니다. 기본 SDK에는 쿼리의 limitToFirst
을 동적으로 수정하는 기능이 없으며 AngularFire2에서 수행 할 방법이 없습니다.
관찰 가능한 query
옵션이 새로운 값을 방출 할 때마다 새로운 Firebase ref가 생성됩니다. source here에서 확인할 수 있습니다.
그러나,이 같은 수행하여 무한한 목록을 나타냅니다 관측 만들 수있을 것입니다 :
import { Observable } from "rxjs/Observable";
import { Subject } from "rxjs/Subject";
import rxjs/add/observable/defer";
import rxjs/add/observable/zip";
import rxjs/add/operator/concatMap";
import rxjs/add/operator/filter";
import rxjs/add/operator/first";
import rxjs/add/operator/map";
import rxjs/add/operator/scan";
import rxjs/add/operator/share";
import rxjs/add/operator/startWith";
const pageSize = 100;
let notifier = new Subject<any>();
let last: Observable<any>;
let infiniteList = Observable
// Use zip to combine the notifier's emissions with the last
// child value:
.zip(notifier, Observable.defer(() => last))
// Use concatMap to emit a page of children into the
// composed observable (note that first is used to complete
// the inner list):
.concatMap(([unused, last]) => this.af.database.list("quests", {
query: {
// If there is a last value, start at that value but ask
// for one more:
limitToFirst: last ? (pageSize + 1) : pageSize,
orderByChild: "date_published",
startAt: last
}
})
.first()
)
// Use scan to accumulate the page into the infinite list:
.scan((acc, list) => {
// If this isn't the initial page, the page was started
// at the last value, so remove it from the beginning of
// the list:
if (acc.length > 0) {
list.shift();
}
return acc.concat(list);
}, [])
// Use share so that the last observable (see below) doesn't
// result in a second subscription:
.share();
// Each time a page is emitted, map to its last child value so
// that it can be fed back into the composed infinite list:
last = infiniteList
.filter((list) => list.length > 0)
.map((list) => list[list.length - 1].date_published)
.startWith(null);
infiniteList.subscribe((list) => console.log(list));
// Each time the notifier emits, another page will be retrieved
// and added to the infinite list:
notifier.next();
notifier.next();
notifier.next();
가 작동하지만 만약 당신이 주문은 AngularFire2을 중복 값을 가지고있는시 아이 this issue이 다시 열리고 해결 될 때까지 결과를 신뢰할 수있게 페이징 할 수 없습니다.
결과 목록은 정적입니다. 즉, 목록에 이미 페이징 된 하위 항목은 데이터베이스가 변경된 경우 업데이트되지 않습니다. 동적 목록을 구현하는 것은 더 어렵습니다. 중복 및 누락 된 하위 항목은 제한 기반 호출 메커니즘으로 쉽게 영향을받을 수 있기 때문입니다.
이 답을 쓰기 때문에, 나는 오픈 소스 화를 중포 기지의 관찰 가능한 라이브러리에 순방향 및 역방향의 가능한 테스트 구현, 비 실시간 및 실시간 무한리스트 관찰 가능한을했습니다. this GitHub repo을 참조하십시오.
전체 목록의 의미는 무엇입니까? 5 항목을 요청했습니다. 그런 다음 10 점을 요구했습니다. 처음 5 점은 요청한 10 점의 일부입니다. 그것은 당신의 기대가 아닌가요? – Rexford
나는 전체 목록이 firebase에서 요청되어 이미로드 된 항목을 다시로드하는 것을 의미했습니다.예상되는 동작이지만 각 상한에 대해 원하는 동작이 아 닌 경우 로딩 시간이 길어집니다. –