File tree Expand file tree Collapse file tree 1 file changed +21
-3
lines changed Expand file tree Collapse file tree 1 file changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -92,9 +92,19 @@ var GCodeInterpreter = (function () {
9292 _classCallCheck ( this , GCodeInterpreter ) ;
9393
9494 this . cmd = '' ;
95+ this . _callbacks = {
96+ 'data' : [ ] ,
97+ 'end' : [ ]
98+ } ;
9599 }
96100
97101 _createClass ( GCodeInterpreter , [ {
102+ key : 'on' ,
103+ value : function on ( evt , callback ) {
104+ this . _callbacks [ evt ] && this . _callbacks [ evt ] . push ( callback ) ;
105+ return this ;
106+ }
107+ } , {
98108 key : 'interpretStream' ,
99109 value : function interpretStream ( stream , callback ) {
100110 var _this = this ;
@@ -105,18 +115,26 @@ var GCodeInterpreter = (function () {
105115 ( function ( ) {
106116 var results = [ ] ;
107117 stream . pipe ( new _gcodeParser . GCodeParser ( ) ) . on ( 'data' , function ( data ) {
118+ _this . _callbacks [ 'data' ] . forEach ( function ( f ) {
119+ f ( data ) ;
120+ } ) ;
108121 results . push ( data ) ;
109122 interpret ( _this , data ) ;
110123 } ) . on ( 'end' , function ( ) {
124+ _this . _callbacks [ 'end' ] . forEach ( function ( f ) {
125+ f ( results ) ;
126+ } ) ;
111127 callback ( null , results ) ;
112- } ) . on ( 'error' , callback ) ;
128+ } ) . on ( 'error' , function ( err ) {
129+ callback ( err ) ;
130+ } ) ;
113131 } ) ( ) ;
114132 } catch ( err ) {
115133 callback ( err ) ;
116- return ;
134+ return this ;
117135 }
118136
119- return stream ;
137+ return this ;
120138 }
121139 } , {
122140 key : 'interpretFile' ,
You can’t perform that action at this time.
0 commit comments