How do I remove all the items from the observable array? It is part of an infinity scroll
https://stackblitz.com/edit/infinite-scroll-firestore?file=app%2Fapp.component.html
this.data = this._data.asObservable()
.pipe(
scan( (acc, val) => {
return this.query.prepend ? val.concat(acc) : acc.concat(val)
})
)
i want to remove everything in the data array. the reset functions didn't do anything to the data observable it just removes from the _data
reset() {
this._data.next([])
}
I also tried setting it to null but it didn't work
reset() {
this._data.next(null)
}
Even if I set it like this
this.data = new Observable
You can apply several higher order functions to mutate the state:
const reset = () => (state) => [];
const add = (newValue) => (state) => [...state, newValue];
const overwrite = (newState) => (state) => newState;
const reset$ = new Subject();
const add$ = new Subject();
const data$ = this._data.asObservable()
...
const data = merge(
reset$.pipe(map(reset)),
add$.pipe(map(add)),
data$.pipe(map(overwrite))
).pipe(
scan((state, fn) => fn(state), [])
);
reset$
will clear your state: reset$.next();
add$
will add the value to your state: add$.next(1);
_data
emits a new value it will overwrite the current stateこの記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加