Last active
February 28, 2019 16:58
-
-
Save nmccready/8027e3a8e168cad6836e0f53c40340bd to your computer and use it in GitHub Desktop.
RxJS Operator Simplification / Creation 6.x
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
export const basic = (subscriber) => (origSource) => | |
origSource.lift({ | |
call(dest, source) { | |
return source.subscribe(subscriber(dest)); | |
} | |
}); | |
export const through = (cb) => | |
basic((dest) => { | |
return { | |
next(msg) { | |
cb(msg, dest); | |
}, | |
error: dest.error, | |
complete: dest.complete | |
}; | |
}); | |
export const bufferThrough = (cb) => { | |
const buffer = []; | |
const throughCb = cb(buffer); | |
// allow closure for handling state w/ buffer | |
/* | |
bufferThrough((buffer) => { | |
let counter = 0 // etc... | |
return (msg, dest) => { | |
} | |
}) | |
*/ | |
return through(throughCb); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reduces something like this ugliness
to