11var utils = require ( "./utils" ) ;
22
3- module . exports = function ( subject , options ) {
4- var globalItems = [
3+ /**
4+ * Apply the operators that apply to the 'file:changed' event
5+ * @param {Rx.Observable } subject
6+ * @param options
7+ * @return {Rx.Observable<{type: string, files: Array<any>}> }
8+ */
9+ function fileChanges ( subject , options ) {
10+ var operators = [
511 {
612 option : "reloadThrottle" ,
713 fnName : "throttle"
@@ -14,16 +20,18 @@ module.exports = function (subject, options) {
1420
1521 var scheduler = options . getIn ( [ "debug" , "scheduler" ] ) ;
1622
23+ /**
24+ * if the 'reloadDebounce' option was provided, create
25+ * a stream buffered/debounced stream of events
26+ */
1727 var initial = ( function ( ) {
1828 if ( options . get ( "reloadDebounce" ) > 0 ) {
19- return getDebouncedStream ( subject , options , scheduler ) ;
29+ return getAggregatedDebouncedStream ( subject , options , scheduler ) ;
2030 }
2131 return subject ;
2232 } ) ( ) ;
2333
24- var withOps = applyOperators ( globalItems , initial , options , scheduler ) ;
25-
26- return withOps
34+ return applyOperators ( operators , initial , options , scheduler )
2735 . map ( function ( xs ) {
2836
2937 var items = [ ] . concat ( xs ) ;
@@ -40,10 +48,17 @@ module.exports = function (subject, options) {
4048 files : items
4149 }
4250 } ) ;
43- } ;
51+ }
52+ module . exports . fileChanges = fileChanges ;
4453
54+ /**
55+ * Apply the operators that apply to the 'browser:reload' event
56+ * @param {Rx.Observable } subject
57+ * @param options
58+ * @returns {Rx.Observable }
59+ */
4560function applyReloadOperators ( subject , options ) {
46- var globalItems = [
61+ var operators = [
4762 {
4863 option : "reloadDebounce" ,
4964 fnName : "debounce"
@@ -58,12 +73,16 @@ function applyReloadOperators (subject, options) {
5873 }
5974 ] ;
6075
61- var scheduler = options . getIn ( [ "debug" , "scheduler" ] ) ;
62-
63- return applyOperators ( globalItems , subject , options , scheduler ) ;
76+ return applyOperators ( operators , subject , options , options . getIn ( [ "debug" , "scheduler" ] ) ) ;
6477}
6578module . exports . applyReloadOperators = applyReloadOperators ;
6679
80+ /**
81+ * @param items
82+ * @param subject
83+ * @param options
84+ * @param scheduler
85+ */
6786function applyOperators ( items , subject , options , scheduler ) {
6887 return items . reduce ( function ( subject , item ) {
6988 var value = options . get ( item . option ) ;
@@ -74,7 +93,12 @@ function applyOperators (items, subject, options, scheduler) {
7493 } , subject ) ;
7594}
7695
77- function getDebouncedStream ( subject , options , scheduler ) {
96+ /**
97+ * @param subject
98+ * @param options
99+ * @param scheduler
100+ */
101+ function getAggregatedDebouncedStream ( subject , options , scheduler ) {
78102 return subject
79103 . filter ( function ( x ) { return options . get ( "watchEvents" ) . indexOf ( x . event ) > - 1 } )
80104 . buffer ( subject . debounce ( options . get ( "reloadDebounce" ) , scheduler ) )
0 commit comments