Skip to content

Commit

Permalink
add override key to make overriding more explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
dcastil committed Aug 20, 2023
1 parent 5857aac commit a22219d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/lib/merge-configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import { Config, ConfigExtension } from './types'
*/
export function mergeConfigs(
baseConfig: Config,
{ cacheSize, prefix, separator, extend = {}, ...configOverride }: ConfigExtension,
{ cacheSize, prefix, separator, extend = {}, override = {} }: ConfigExtension,
) {
overrideProperty(baseConfig, 'cacheSize', cacheSize)
overrideProperty(baseConfig, 'prefix', prefix)
overrideProperty(baseConfig, 'separator', separator)

for (const configKey in configOverride) {
for (const configKey in override) {
overrideConfigProperties(
baseConfig[configKey as keyof typeof configOverride],
configOverride[configKey as keyof typeof configOverride],
baseConfig[configKey as keyof typeof override],
override[configKey as keyof typeof override],
)
}

Expand Down
23 changes: 13 additions & 10 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export interface Config {
export interface Config extends ConfigStatic, ConfigGroups {}

interface ConfigStatic {
/**
* Integer indicating size of LRU cache used for memoizing results.
* - Cache might be up to twice as big as `cacheSize`
Expand All @@ -19,6 +21,13 @@ export interface Config {
* Theme scales used in classGroups.
* The keys are the same as in the Tailwind config but the values are sometimes defined more broadly.
*/
}

interface ConfigGroups {
/**
* Theme scales used in classGroups.
* The keys are the same as in the Tailwind config but the values are sometimes defined more broadly.
*/
theme: ThemeObject
/**
* Object with groups of classes.
Expand Down Expand Up @@ -46,15 +55,9 @@ export interface Config {
conflictingClassGroupModifiers: Record<ClassGroupId, readonly ClassGroupId[]>
}

export type ConfigExtend = Partial<
Pick<
Config,
'theme' | 'classGroups' | 'conflictingClassGroups' | 'conflictingClassGroupModifiers'
>
>

export interface ConfigExtension extends Partial<Config> {
extend?: ConfigExtend
export interface ConfigExtension extends Partial<ConfigStatic> {
override?: Partial<ConfigGroups>
extend?: Partial<ConfigGroups>
}

export type ThemeObject = Record<string, ClassGroup>
Expand Down

0 comments on commit a22219d

Please sign in to comment.