0.2.3 • Published 10 years ago

data-stream v0.2.3

Weekly downloads
6
License
MIT
Repository
github
Last release
10 years ago

#data-stream Build Status

A Promise like data-stream implementation.

##Installing

  • npm:

      $ npm install --save data-stream
  • bower

      $ bower install --save data-stream

##Documentation

const Stream = require('data-stream')
const s = new Stream()

###Stream Class

The Stream Class is responsible to receive the data from the broadcaster

####Methods

  • notify(data: any) : None

    Send information to this and all child streams

  • then(callback: Function) : Stream

    Generates a child stream that applies a extra callback

  • map(callback: Function) : Stream

    Just like then, but applies the callback to each element of the data instead of to the data itself

Examples:

Setting up streams:

const Stream = require('data-stream');
const s = new Stream();
let stream1 = s.then(() => console.log("stream 1 exec 1"))
		.then(() => console.log("stream 1 exec 2"))
		.then(() => console.log("stream 1 exec 3"));
let stream2 = s.then(() => console.log("stream 2 exec 1"))
		.then(() => console.log("stream 2 exec 2"))
		.then(() => console.log("stream 2 exec 3"));
s.notify();
//stream 1 exec 1
//stream 1 exec 2
//stream 1 exec 3
//stream 2 exec 1
//stream 2 exec 2
//stream 2 exec 3

Transforming data:

const Broadcaster = require('data-stream');
const s = new Stream();
s.map((el) => el+1)
		.then(data => console.log(data));
s.notify([1,2,3]);
//[2,3,4]

##Why ? this package was built to easily manage asynchronous data between a service and several controllers on angular.

0.2.3

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago