Skip to content

Commit

Permalink
golf: use arrow instead of functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sastan committed Jan 21, 2021
1 parent 3f91827 commit 70b013b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 35 deletions.
49 changes: 25 additions & 24 deletions src/css/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,31 +205,32 @@ export const keyframes: CSSFactory<CSSAtKeyframes, CSSAtKeyframes | CSSPropertie
* })
* ```
*/
export function animation(
value: string | CSSRules | ((context: Context) => string),
): CSSFactory<CSSAtKeyframes, CSSAtKeyframes | CSSProperties, CSSDirective>
export interface Animation {
(value: string | CSSRules | ((context: Context) => string)): CSSFactory<
CSSAtKeyframes,
CSSAtKeyframes | CSSProperties,
CSSDirective
>

export function animation(
value: string | CSSRules | ((context: Context) => string),
waypoints: CSSAtKeyframes | CSSKeyframes,
): CSSDirective
(
value: string | CSSRules | ((context: Context) => string),
waypoints: CSSAtKeyframes | CSSKeyframes,
): CSSDirective
}

export function animation(
export const animation = ((
value: string | CSSRules | ((context: Context) => string),
waypoints?: CSSAtKeyframes | CSSKeyframes,
): CSSDirective | CSSFactory<CSSAtKeyframes, CSSAtKeyframes | CSSProperties, CSSDirective> {
if (waypoints === undefined) {
return ((...args: Parameters<typeof keyframes>): CSSDirective =>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
animation(value, keyframes(...(args as any)))) as CSSFactory<
CSSAtKeyframes,
CSSAtKeyframes | CSSProperties,
CSSDirective
>
}

return css({
...(is.object(value) ? value : { animation: value }),
animationName: is.function(waypoints) ? waypoints : keyframes(waypoints),
})
}
): CSSDirective | CSSFactory<CSSAtKeyframes, CSSAtKeyframes | CSSProperties, CSSDirective> =>
waypoints === undefined
? (((...args: Parameters<typeof keyframes>): CSSDirective =>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
animation(value, keyframes(...(args as any)))) as CSSFactory<
CSSAtKeyframes,
CSSAtKeyframes | CSSProperties,
CSSDirective
>)
: css({
...(is.object(value) ? value : { animation: value }),
animationName: is.function(waypoints) ? waypoints : keyframes(waypoints),
})) as Animation
20 changes: 9 additions & 11 deletions src/twind/apply.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import type { Token, ApplyDirective, TW, Context } from '../types'
import type { Token, ApplyDirective, Context } from '../types'

import { parse } from './parse'
import { directive } from './directive'

const applyFactory = (tokens: unknown[], { css }: Context) => css(parse(tokens))

export function apply(
this: TW | null | undefined | void,
strings: TemplateStringsArray,
...interpolations: Token[]
): ApplyDirective

export function apply(...tokens: Token[]): ApplyDirective
export interface Apply {
(strings: TemplateStringsArray, ...interpolations: Token[]): ApplyDirective

export function apply(...tokens: unknown[]): ApplyDirective {
return directive(applyFactory, tokens)
(...tokens: Token[]): ApplyDirective
}

const applyFactory = (tokens: unknown[], { css }: Context) => css(parse(tokens))

export const apply: Apply = (...tokens: unknown[]): ApplyDirective =>
directive(applyFactory, tokens)

0 comments on commit 70b013b

Please sign in to comment.