Skip to content

Instantly share code, notes, and snippets.

@Raynos
Created September 15, 2012 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raynos/3727525 to your computer and use it in GitHub Desktop.
Save Raynos/3727525 to your computer and use it in GitHub Desktop.
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
}
}
}
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