cumberbatch
Advanced tools
Comparing version 0.1.15 to 0.1.16
var minimatch = require('minimatch'); | ||
var oid = require('oid'); | ||
var MinimatchTree = require('./MinimatchTree'); | ||
var GlobEmitter = function(options) { | ||
@@ -9,2 +11,3 @@ this._options = options || {}; | ||
this._hashLookup = {}; | ||
this._patternTree = new MinimatchTree(); | ||
@@ -29,2 +32,3 @@ if (typeof this._options.debounceMs !== 'number') { | ||
if (listeners[j].hash === hash) { | ||
this._patternTree.remove(glob, listeners[j]); | ||
this._globListeners[glob].splice(j, 1); | ||
@@ -52,2 +56,3 @@ j--; | ||
this._globListeners[glob].push(listener); | ||
this._patternTree.add(glob, listener); | ||
} | ||
@@ -78,42 +83,17 @@ | ||
var globData = this._nextEvent.globs; | ||
var paths = Object.keys(globData); | ||
this._nextEvent = null; | ||
var callbackHash; | ||
var negatedPaths = {}; | ||
var callbackData = {}; | ||
var callbacks = {}; | ||
for (var path in globData) { | ||
for (var glob in this._globListeners) { | ||
var isNegation = glob.indexOf('!') === 0; | ||
var usedGlob = isNegation ? glob.substr(1) : glob; | ||
if (minimatch(path, usedGlob)) { | ||
var listeners = this._globListeners[glob]; | ||
for (var i = 0; i < listeners.length; i++) { | ||
callbackHash = listeners[i].hash; | ||
if (!callbacks[callbackHash]) { | ||
callbacks[callbackHash] = listeners[i].fn; | ||
callbackData[callbackHash] = {}; | ||
negatedPaths[callbackHash] = {}; | ||
} | ||
if (isNegation) { | ||
negatedPaths[callbackHash][path] = true; | ||
delete callbackData[callbackHash][path]; | ||
} else if (!negatedPaths[callbackHash][path]) { | ||
callbackData[callbackHash][path] = globData[path]; | ||
} | ||
} | ||
} | ||
var calls = this._patternTree.find(paths); | ||
for (var i = 0; i < calls.length; i++) { | ||
var call = calls[i]; | ||
var callData = {}; | ||
for (var j = 0; j < call.files.length; j++) { | ||
callData[call.files[j]] = globData[call.files[j]]; | ||
} | ||
} | ||
for (callbackHash in callbacks) { | ||
if (Object.keys(callbackData[callbackHash]).length) { | ||
try { | ||
callbacks[callbackHash](callbackData[callbackHash]); | ||
} catch (e) { | ||
console.error(e, e.stack); | ||
} | ||
try { | ||
call.data.fn(callData); | ||
} catch (e) { | ||
console.error(e, e.stack); | ||
} | ||
@@ -120,0 +100,0 @@ } |
{ | ||
"name": "cumberbatch", | ||
"description": "crazy watcher stuff", | ||
"version": "0.1.15", | ||
"version": "0.1.16", | ||
"homepage": "https://github.com/azulus/cumberbatch", | ||
@@ -6,0 +6,0 @@ "authors": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
52364
13
1489