Last active
December 3, 2017 18:23
-
-
Save LironHazan/82d983d0151a0dce47b4280598f84e62 to your computer and use it in GitHub Desktop.
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
const Rx = require('rxjs'); | |
class AnimalsService { | |
constructor(data){ | |
this._source = data; | |
} | |
// lazy loading, client will ask for x items (limit) it will be the length of the returned array, | |
simplePager(pageIndex=0, limit=10, data) { | |
const deleteCount = pageIndex*limit; | |
const source$ = Rx.Observable.from(this._source || data) | |
.reduce((acc, value, index) => { | |
if(deleteCount <= index) { | |
acc.push(value); | |
} | |
return acc; | |
}, []); | |
const observer = { | |
next: i => {console.log(JSON.stringify(i))}, | |
error: err => {console.log(err)}, | |
complete: () => {} | |
}; | |
source$.subscribe(observer); | |
return source$.toPromise(); | |
} | |
} | |
module.exports = AnimalsService; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment