Created
September 15, 2012 12:13
-
-
Save Raynos/3727525 to your computer and use it in GitHub Desktop.
This file contains 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
var insert = require("insert-stream") | |
, through = require("through-stream") | |
var insertInto = insert(rootElem, null) | |
// Some data source | |
source.pipe(infiniteScroll()).pipe(insertInto) | |
function infiniteScroll() { | |
return through(write) | |
function write(chunk, buffer) { | |
var stream = this | |
buffer.push(chunk) | |
// isBelowScreen logic. not implemented | |
if (chunk.isBelowScreen()) { | |
// some screen object. not implemented | |
screen.on("scrolled", function () { stream.emit("drain") } | |
return false | |
} | |
} | |
} |
This file contains 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
var insert = require("insert-stream") | |
, proxy = require("proxy-stream") | |
var insertInto = insert(rootElem, null) | |
source.pipe(infiniteScroll(insertInto)) | |
function infiniteScroll(stream) { | |
return proxy(stream, write, stream.read, stream.end, [writePipe]) | |
function write(chunk) { | |
var res = stream.write(chunk) | |
// isBelowScreen logic. not implemented | |
if (chunk.isBelowScreen()) { | |
// some screen object. not implemented | |
screen.on("scrolled", function () { scroll.emit("drain") } | |
return false | |
} | |
return res | |
} | |
function writePipe(chunk, buffer) { | |
var stream = this | |
buffer.push(chunk) | |
if (chunk.isBelowScreen()) { | |
screen.on("scrolled", function () { stream.emit("drain") } | |
return false | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment