This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 975
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10289 from brave/fix/9987
Fix isResourceEnabled jank using a cache
- Loading branch information
Showing
5 changed files
with
78 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* 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/. */ | ||
|
||
'use strict' | ||
|
||
const appConstants = require('../../../js/constants/appConstants') | ||
const {clearBraverySettingsCache} = require('../../common/cache/braverySettingsCache') | ||
const {makeImmutable} = require('../../common/state/immutableUtil') | ||
|
||
const braverySettingsReducer = (state, action, immutableAction) => { | ||
action = immutableAction || makeImmutable(action) | ||
switch (action.get('actionType')) { | ||
case appConstants.APP_SET_RESOURCE_ENABLED: | ||
case appConstants.APP_CHANGE_SITE_SETTING: | ||
case appConstants.APP_REMOVE_SITE_SETTING: | ||
case appConstants.APP_CLEAR_SITE_SETTINGS: | ||
clearBraverySettingsCache() | ||
break | ||
} | ||
return state | ||
} | ||
|
||
module.exports = braverySettingsReducer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* 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/. */ | ||
|
||
/** | ||
* Cache of URLs mapped their site settings. | ||
* This gets rebuilt when site settings or a bravery setting is changed. | ||
*/ | ||
const currentBraverySettingsCache = new Map() | ||
|
||
const clearBraverySettingsCache = () => { | ||
currentBraverySettingsCache.clear() | ||
} | ||
|
||
const getBraverySettingsCache = (url) => { | ||
return currentBraverySettingsCache.get(url) | ||
} | ||
|
||
const updateBraverySettingsCache = (url, braverySettings) => { | ||
currentBraverySettingsCache.set(url, braverySettings) | ||
} | ||
|
||
module.exports = { | ||
clearBraverySettingsCache, | ||
getBraverySettingsCache, | ||
updateBraverySettingsCache | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters