stream-mixin

0.0.0 • Public • Published

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.

Build status

Browser support

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

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i stream-mixin

Weekly Downloads

2

Version

0.0.0

License

MIT

Last publish

Collaborators

  • michaelrhodes