A classic-stream mixin for browser code.
JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
build
test
.travis.yml
index.js
package.json
readme.md

readme.md

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