a function you can replace.
npm install replaceable-function
var handler = Replaceable(start)
stream.on('data', handler)
function start(data) {
// handle connection initialisation
…
handler.replace(handle)
}
function handle(data) {
// handle the data
if (data.last)
handler.replace(end)
else
…
}
function end(data) {
// handle the goodbye
…
handler.replace(null)
}
Returns a function that delegates to its internal function.
If the passed value isn't a function, it'll be replaced by function() { throw new TypeError('not a function') }
.
Returns a function that delegates to its internal function.
If the passed value isn't a function, it'll be replaced by function() {}
.
replaces the internal function.