Skip to content
This repository has been archived by the owner on Jun 6, 2019. It is now read-only.

do now allow duplicated items for resources blocked #43

Merged
merged 5 commits into from
Jul 6, 2018
Merged

Conversation

cezaraugusto
Copy link
Contributor

fix brave/brave-browser#420

Test Plan:

covered by automated tests

-
this allows iterating of iterators
which is useful for array deduping using Set() for example
@see https://www.typescriptlang.org/docs/handbook/iterators-and-generators.html
@cezaraugusto cezaraugusto self-assigned this Jul 2, 2018
@cezaraugusto cezaraugusto requested a review from yrliou July 2, 2018 22:51
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

export const unique = (arr: Array<string>) => [...new Set(arr)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice way to deduplicate items :)

const newProps = Object.assign(fakeProps, {
adsBlockedResources: [
'https://everbodys-got-something-to-hide-except-me-and-my-monkey.cool',
'https://everbodys-got-something-to-hide-except-me-and-my-monkey.cool'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐒

@@ -74,22 +75,22 @@ export const updateResourceBlocked: shieldState.UpdateResourceBlocked = (state,

if (blockType === 'ads') {
tabs[tabId].adsBlocked++
tabs[tabId].adsBlockedResources = [ ...tabs[tabId].adsBlockedResources, subresource ]
tabs[tabId].adsBlockedResources = unique([ ...tabs[tabId].adsBlockedResources, subresource ])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our block counts will not match the counts of resources we are showing, I think it might be better to match both.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe set adsBlocked to the length of adsBlockedResources after this line?

Copy link
Member

@bbondy bbondy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changing to request changes for the comment.

@cezaraugusto
Copy link
Contributor Author

ok ready w/ updates:

Note: an ad that is also blocked as tracker is kept as-is and not deduped. Visiting https://cezaraugusto.net will show 2 resources blocked with the same analytics url. Workaround for this took a lot of code changes and not worth the effort. Better take would be just making clear for adblock what/what not is an ad/tracker.

@bbondy bbondy merged commit 9b5332a into master Jul 6, 2018
@bsclifton bsclifton deleted the shields/420 branch September 26, 2018 05:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Blocked items lists multiple time on page reload
3 participants