0.0.0 • Published 11 years ago
stream-mixin v0.0.0
stream-mixin
stream-mixin is a classic-stream mixin for browser code. It uses the functional mixin pattern to add classic stream functionality to your objects.
Install
$ npm install stream-mixin
…or just grab a pre-built standalone version from the project’s build directory.
Usage
var stream = require('stream-mixin')
// Make a stream from an Object…
var mailman = {}
stream.call(mailman)
mailman.writable = true
mailman.write = function(data) {
if (/!/.test(data)) {
mailman.emit('data', 'ARRGH!')
}
}
// …or a Class
var Dog = function() {}
var dog = new Dog
stream.call(Dog.prototype)
Dog.prototype.readable = true
Dog.prototype.bark = function() {
this.emit('data', 'woof!')
}
// Listen to events explicitly…
mailman.on('data', function(data) {
console.log('mailman says: ' + data)
})
// …or implictly
dog.pipe(mailman)
// Ok, go!
dog.bark()
Note
juliangruber’s module is almost identical to this one, but it depends on the component package manager.
License
0.0.0
11 years ago