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

Commit

Permalink
Merge pull request #2298 from ethcore/jg-no-bg-regen
Browse files Browse the repository at this point in the history
local cache of generated background (no allocation on each re-render)
  • Loading branch information
jacogr authored Sep 23, 2016
2 parents 40964cc + 76d5397 commit 7cfbd3a
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions js/src/ui/Theme/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,29 @@ muiTheme.textField.disabledTextColor = muiTheme.textField.textColor;
muiTheme.toolbar = lightTheme.toolbar;
muiTheme.toolbar.backgroundColor = 'transparent';

const imageCache = {};

muiTheme.parity = {
backgroundSeed: '0x0',

setBackgroundSeed: (seed) => {
muiTheme.parity.backgroundSeed = seed;
},

getBackgroundStyle: (gradient = 'rgba(255, 255, 255, 0.25)') => {
const url = GeoPattern.generate(muiTheme.parity.backgroundSeed).toDataUrl();
getBackgroundStyle: (_gradient, _seed) => {
const gradient = _gradient || 'rgba(255, 255, 255, 0.25)';
const seed = _seed || muiTheme.parity.backgroundSeed;
let url;

if (_seed) {
url = GeoPattern.generate(_seed).toDataUrl();
} else if (imageCache[seed] && imageCache[seed][gradient]) {
url = imageCache[seed][gradient];
} else {
url = GeoPattern.generate(seed).toDataUrl();
imageCache[seed] = imageCache[seed] || {};
imageCache[seed][gradient] = url;
}

return {
background: `linear-gradient(${gradient}, ${gradient}), ${url}`
Expand Down

0 comments on commit 7cfbd3a

Please sign in to comment.