Index: lib/snippets.js |
=================================================================== |
--- a/lib/snippets.js |
+++ b/lib/snippets.js |
@@ -16,53 +16,69 @@ |
*/ |
"use strict"; |
/** |
* @fileOverview Snippets implementation. |
*/ |
+const {EventEmitter} = require("./events"); |
const {Filter} = require("./filterClasses"); |
const singleCharacterEscapes = new Map([ |
["n", "\n"], ["r", "\r"], ["t", "\t"] |
]); |
let filters = new Set(); |
/** |
* Container for snippet filters |
* @class |
*/ |
-let Snippets = { |
+let Snippets = Object.assign(new EventEmitter(), { |
/** |
* Removes all known filters |
*/ |
clear() |
{ |
+ if (filters.size == 0) |
+ return; |
+ |
filters.clear(); |
+ |
+ this.emit("snippets.filtersCleared"); |
}, |
/** |
* Add a new snippet filter |
* @param {SnippetFilter} filter |
*/ |
add(filter) |
{ |
+ let {size} = filters; |
+ |
filters.add(filter.text); |
+ |
+ if (size != filters.size) |
+ this.emit("snippets.filterAdded", filter); |
}, |
/** |
* Removes a snippet filter |
* @param {SnippetFilter} filter |
*/ |
remove(filter) |
{ |
+ let {size} = filters; |
+ |
filters.delete(filter.text); |
+ |
+ if (size != filters.size) |
+ this.emit("snippets.filterRemoved", filter); |
}, |
/** |
* Returns a list of all scripts active on a particular domain |
* @param {string} domain |
* @return {string[]} |
*/ |
getScriptsForDomain(domain) |
@@ -71,17 +87,17 @@ |
for (let text of filters) |
{ |
let filter = Filter.fromText(text); |
if (filter.isActiveOnDomain(domain)) |
result.push(filter.script); |
} |
return result; |
} |
-}; |
+}); |
exports.Snippets = Snippets; |
/** |
* Parses a script and returns a list of all its commands and their arguments |
* @param {string} script |
* @return {Array.<string[]>} |
*/ |