(changedPath, event)
| 106 | |
| 107 | // reload the browser |
| 108 | function onChange(changedPath, event) { |
| 109 | var _ref = path.extname(changedPath), |
| 110 | action = cssExtensions.indexOf(_ref) >= 0 ? 'updateCSS' : 'reload'; |
| 111 | //first change is with delayTime delay , thereafter only once there has been no further changes for guardTime seconds |
| 112 | |
| 113 | //validate the change |
| 114 | if (customOnChange.validate) { |
| 115 | if (!customOnChange.validate(changedPath, event,action)) { return ;} //ignore changes if the app says-so |
| 116 | } |
| 117 | |
| 118 | //avoid multiple rapid changes |
| 119 | var delay=delayTime; |
| 120 | if (lastRun[action].guardTime) { clearTimeout(lastRun[action].guardTime); delay=guardTime;} |
| 121 | if (lastRun[action].delayTime) { clearTimeout(lastRun[action].delayTime); delay=delayTime;} |
| 122 | lastRun[action].delayTime = setTimeout(function(){ |
| 123 | onChangeFiltered(changedPath, event, action); |
| 124 | lastRun[action].guardTime = setTimeout(function(){ |
| 125 | lastRun[action].guardTime=null; |
| 126 | }, delay); |
| 127 | lastRun[action].delayTime=null; |
| 128 | }, delay); |
| 129 | |
| 130 | return Date.now(); |
| 131 | } |
| 132 | |
| 133 | return onChange(changedPath, event); |
| 134 | } |
no test coverage detected