Skip to content

Commit

Permalink
feat(cache): add option to disable xstyled cache (#379)
Browse files Browse the repository at this point in the history
Also document it.
  • Loading branch information
mleralec authored Oct 5, 2022
1 parent fd0a097 commit 738f882
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/system/src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ const cacheSupported: boolean =

const caches = cacheSupported ? new WeakMap<ITheme, ThemeCache>() : null

const isCacheDisabled = (theme: ITheme): boolean =>
theme?.xstyled?.cache === false

const getThemeCache = (theme: ITheme): ThemeCache | null => {
const cacheDisabled = isCacheDisabled(theme)
if (cacheDisabled) return null
if (caches === null) return null
if (caches.has(theme)) return caches.get(theme) || null
const cache = {}
Expand Down
3 changes: 3 additions & 0 deletions packages/system/src/defaultTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,9 @@ export const defaultTheme = {
disabled: '&:disabled, &[aria-disabled=true]',
placeholder: '&::placeholder',
},
xstyled: {
cache: true,
},
}

export type DefaultTheme = typeof defaultTheme
24 changes: 24 additions & 0 deletions website/pages/docs/customization/cache.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
section: Customization
title: Colors
slug: /docs/colors/
order: 4
---

# Cache

Customizing the cache behaviour of xstyled.

<carbon-ad />

## Turn off cache

By default xstyled cache every property resolution. If you need to disabled the cache behaviour, you can do it in the theme.

```js
export const theme = {
xstyled: {
cache: false,
},
}
```

0 comments on commit 738f882

Please sign in to comment.