Created
January 20, 2019 14:42
-
-
Save ThePenguin1140/0c973715aa1776a648c6136cdb08b5c4 to your computer and use it in GitHub Desktop.
Manual pages because you like reinventing the wheel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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