Skip to content

Commit

Permalink
chore: add explaining comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yarastqt committed Apr 26, 2020
1 parent dabf159 commit fe971a9
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import deepmerge from 'deepmerge'
import { Shape, ThemeTokens } from './core/types'
import { esModuleInterop } from './core/import-module'

// For better DX, theme can be polymorphed, for example:
// withTokens(() => ...),
// withTokens(withTokens(() => ...), () => ...)
// withTokens(withTokens(() => ...)(), () => ...)
type ThemeFn<T> = ThemeFn1<T> | ThemeFn2<T>
type ThemeFn1<T> = (primitives: T) => ThemeTokens
type ThemeFn2<T> = (primitives: T) => ThemeFn1<T>
Expand All @@ -13,6 +17,7 @@ export function withTokens<T extends Shape<any>, U extends Shape<any> = Shape<an
) {
return (primitives1?: T) => (primitives2?: U) => {
const composedPrimitives = deepmerge(primitives1 || {}, primitives2 || {})
// Interop needed for using transpiled esm modules.
const theme1 = esModuleInterop<ThemeFn1<any>>(themeFn1 as any)
const theme2 = esModuleInterop<ThemeFn1<any>>(themeFn2 as any)
if (theme2 === undefined) {
Expand Down

0 comments on commit fe971a9

Please sign in to comment.