Skip to content

Instantly share code, notes, and snippets.

@ThePenguin1140
Created January 20, 2019 14:42
Show Gist options
  • Save ThePenguin1140/0c973715aa1776a648c6136cdb08b5c4 to your computer and use it in GitHub Desktop.
Save ThePenguin1140/0c973715aa1776a648c6136cdb08b5c4 to your computer and use it in GitHub Desktop.
Manual pages because you like reinventing the wheel
interface IItem {
page: number;
content: number;
}
class Paging {
const ITEM_LIMIT: number = 10;
const CONTENT_FILTER: number = 2;
const content$: Subject<IItem[]>;
const filteredContent$: Observable<IItem[]>;
let pageCounter: number = 0;
constructor() {
this.content$ = new Subject<IItem[]>();
this.filteredContent$ = this.content$.pipe(
map(items => _.filter(items, i => i.content === this.CONTENT_FILTER)),
tap(filteredItems =>
if(filteredItems.length < this.ITEM_LIMIT) this._getNextPage()
),
)
}
/*
* PRIVATE FUNCTIONS
*/
private _getNextPage(): Observable<IItem[]> {
for(let i = 0; i < 10; i++ ) {
this.content$.next({
page: pageCounter,
content: i,
});
}
this.pageCounter++;
return content$;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment