Make filter classes private
Background
The APIs of Core are going in the direction of using strings and plain objects (e.g. see https://issues.adblockplus.org/ticket/7094). To continue with this work, the next step would be to make all the filter classes except the base class Filter
private to lib/filterClasses.js
. Any client code that wants to check the type of a filter object should use the type
property rather than the instanceof
operator. This would allow us to reuse objects, create them on the fly, and so on, while exposing only a single API: Filter.fromText()
.
A Filter
object returned by the fromText()
function should also be considered immutable, whether or not this is actually enforced by the code (e.g. by only having getters for the properties).
What to change
At a high level:
- In
lib/filterClasses.js
, stop exporting anything other than theFilter
class with itsfromText()
andfromObject()
functions, unless necessary. If something must be exported only for other code in Core, it should be marked@package
in JSDoc. - In any other part of the code, replace code like
filter instanceof BlockingFilter
withfilter.type == "blocking"
.