improved README

This commit is contained in:
Philipp Kunz 2016-09-25 16:28:42 +02:00
parent aabfb2721d
commit b24b564495
4 changed files with 53 additions and 21 deletions

View File

@ -31,6 +31,7 @@ let mySmartstream = new Smartstream([
]) ])
mySmartstream.onError((err) => { /* handle error */ }) // handles all errors in stream mySmartstream.onError((err) => { /* handle error */ }) // handles all errors in stream
myStream.onCustomEvent('myeventname', (args...) => { /* Do something */ }) // emit an custom event anywhere in your stream
mySmartstream.run().then(() => {/* do something when stream is finished */}) mySmartstream.run().then(() => {/* do something when stream is finished */})
``` ```

20
dist/index.d.ts vendored
View File

@ -3,9 +3,6 @@ import * as plugins from './smartstream.plugins';
export interface IErrorFunction { export interface IErrorFunction {
(err: any): any; (err: any): any;
} }
export interface IStreamStartFunction {
(stream: any): any;
}
export interface ICustomEventFunction { export interface ICustomEventFunction {
(): any; (): any;
} }
@ -17,10 +14,13 @@ export interface ICustomEventObject {
* class Smartstream handles * class Smartstream handles
*/ */
export declare class Smartstream { export declare class Smartstream {
streamArray: any[]; private streamArray;
errorFunction: IErrorFunction; private errorFunction;
streamStartFunction: IStreamStartFunction; private customEventObjectArray;
customEventObjectArray: ICustomEventObject[]; private streamStartedDeferred;
/**
* constructor
*/
constructor(streamArrayArg: any[]); constructor(streamArrayArg: any[]);
/** /**
* attach an error handler to the stream to prevent throwing * attach an error handler to the stream to prevent throwing
@ -29,7 +29,11 @@ export declare class Smartstream {
/** /**
* make something with the stream itself * make something with the stream itself
*/ */
onStreamStart(): plugins.q.Promise<any>; streamStarted(): plugins.q.Promise<any>;
/**
* attach listener to custom event
*/
onCustomEvent(eventNameArg: string, eventFunctionArg: ICustomEventFunction): void;
/** /**
* run the stream * run the stream
* @returns Promise * @returns Promise

20
dist/index.js vendored
View File

@ -4,11 +4,14 @@ const plugins = require("./smartstream.plugins");
* class Smartstream handles * class Smartstream handles
*/ */
class Smartstream { class Smartstream {
/**
* constructor
*/
constructor(streamArrayArg) { constructor(streamArrayArg) {
this.streamArray = []; this.streamArray = [];
this.errorFunction = null; this.errorFunction = null;
this.streamStartFunction = null;
this.customEventObjectArray = []; this.customEventObjectArray = [];
this.streamStartedDeferred = plugins.q.defer();
this.streamArray = streamArrayArg; this.streamArray = streamArrayArg;
} }
/** /**
@ -20,7 +23,17 @@ class Smartstream {
/** /**
* make something with the stream itself * make something with the stream itself
*/ */
onStreamStart() { streamStarted() {
return this.streamStartedDeferred.promise;
}
/**
* attach listener to custom event
*/
onCustomEvent(eventNameArg, eventFunctionArg) {
this.customEventObjectArray.push({
eventName: eventNameArg,
eventFunction: eventFunctionArg
});
} }
/** /**
* run the stream * run the stream
@ -51,6 +64,7 @@ class Smartstream {
} }
firstIteration = false; firstIteration = false;
} }
this.streamStartedDeferred.resolve();
finalStream.on('end', function () { finalStream.on('end', function () {
done.resolve(); done.resolve();
}); });
@ -64,4 +78,4 @@ class Smartstream {
} }
} }
exports.Smartstream = Smartstream; exports.Smartstream = Smartstream;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsaURBQWdEO0FBbUJoRDs7R0FFRztBQUNIO0lBS0ksWUFBWSxjQUFxQjtRQUpqQyxnQkFBVyxHQUFHLEVBQUUsQ0FBQTtRQUNoQixrQkFBYSxHQUFtQixJQUFJLENBQUE7UUFDcEMsd0JBQW1CLEdBQXlCLElBQUksQ0FBQTtRQUNoRCwyQkFBc0IsR0FBeUIsRUFBRSxDQUFBO1FBRTdDLElBQUksQ0FBQyxXQUFXLEdBQUcsY0FBYyxDQUFBO0lBQ3JDLENBQUM7SUFFRDs7T0FFRztJQUNILE9BQU8sQ0FBQyxnQkFBZ0M7UUFDcEMsSUFBSSxDQUFDLGFBQWEsR0FBRyxnQkFBZ0IsQ0FBQTtJQUN6QyxDQUFDO0lBRUQ7O09BRUc7SU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LENBQUMsT0FBTyxDQUFBO0lBQ3ZCLENBQUM7Q0FDSjtBQWhGRCxrQ0FnRkMifQ==

View File

@ -4,10 +4,6 @@ export interface IErrorFunction {
(err): any (err): any
} }
export interface IStreamStartFunction {
(stream): any
}
export interface ICustomEventFunction { export interface ICustomEventFunction {
(): any (): any
} }
@ -21,10 +17,14 @@ export interface ICustomEventObject {
* class Smartstream handles * class Smartstream handles
*/ */
export class Smartstream { export class Smartstream {
streamArray = [] private streamArray = []
errorFunction: IErrorFunction = null private errorFunction: IErrorFunction = null
streamStartFunction: IStreamStartFunction = null private customEventObjectArray: ICustomEventObject[] = []
customEventObjectArray: ICustomEventObject[] = [] private streamStartedDeferred = plugins.q.defer()
/**
* constructor
*/
constructor(streamArrayArg: any[]) { constructor(streamArrayArg: any[]) {
this.streamArray = streamArrayArg this.streamArray = streamArrayArg
} }
@ -39,8 +39,18 @@ export class Smartstream {
/** /**
* make something with the stream itself * make something with the stream itself
*/ */
onStreamStart(): plugins.q.Promise<any> { streamStarted(): plugins.q.Promise<any> {
return this.streamStartedDeferred.promise
}
/**
* attach listener to custom event
*/
onCustomEvent(eventNameArg: string, eventFunctionArg: ICustomEventFunction) {
this.customEventObjectArray.push({
eventName: eventNameArg,
eventFunction: eventFunctionArg
})
} }
/** /**
@ -72,6 +82,9 @@ export class Smartstream {
} }
firstIteration = false firstIteration = false
} }
this.streamStartedDeferred.resolve()
finalStream.on('end',function(){ finalStream.on('end',function(){
done.resolve() done.resolve()
}) })