Move filter state to a global map
Background
This is a reboot of https://issues.adblockplus.org/ticket/7453
We have now stopped referring to the filter classes in the rest of eyeo/adblockplus/adblockpluscore> (#157 (closed), #159 (closed)) and the next step is to make the classes private (#19). Before we do this, we still need to address the issue that the state of a filter lives with the filter object itself. The last time we discussed this, we got caught up in discussions about what the API should look like exactly.
I'd like to propose a new filterState
module with the following functions:
State: enabled
isEnabled(filterText: string): boolean
setEnabled(filterText: string, enabled: boolean)
toggleEnabled(filterText: string)
resetEnabled(filterText: string)
State: hitCount
getHitCount(filterText: string): number
setHitCount(filterText: string, hitCount: number)
resetHitCount(filterText: string)
State: lastHit
getLastHit(filterText: string): number
setLastHit(filterText: string, lastHit: number)
resetLastHit(filterText: string)
Hits
registerHit(filterText: string)
resetHits(filterText: string)
Reset
reset(filterText: string)
Serialization
*serialize(filterText: string)
fromObject(filterText: string, object: object)
Additionally, in this proposal, the filter.disabled
, filter.hitCount
, and filter.lastHit
events emitted by filterNotifier
are now replaced with filterState.enabled
(note: not disabled
), filterState.hitCount
, and filterState.lastHit
and include the filter text rather than the filter object.
What to change
See !248 (closed).
Related issues
There is #115 (closed) for keeping a disabled state at the subscription level.
There is follow-up issue #199 (closed) for writing tests for lib/filterState.js
.