Skip to content

Commit

Permalink
Move chainable notation to type alias
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii Kirmas committed Feb 24, 2021
1 parent 5c568c5 commit 933a1ae
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions src/direct.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,40 @@ describe(direct.name, () => {
).toBe(
className
))
it("called", () => expect({
...output({

describe("chained", () => {
const chained = output({
class3: undefined, class4: "hash4"
})
}).toStrictEqual({
"className": `${className} class3 hash4`
}))
it("called is strigable", () => expect(
`${output({
class3: undefined, class4: "hash4"
})}`
).toBe(
`${className} class3 hash4`
))
, nextClassName = `${className} class3 hash4`

it("called", () => expect({
...chained
}).toStrictEqual({
className: nextClassName
}))
it("called is strigable", () => expect(
`${chained}`
).toBe(
nextClassName
))
it("TBD call is not allow by TS on key duplication", () => expect(
//TODO //@ts-expect-error`
`${chained({class1: undefined})}`
).toBe(
`${nextClassName} class1`
))
})
})

type ClassNamingChain = {
className: string
(classes: Record<string, ClassValue>): ClassNamingChain
}

function direct<T extends Record<string, ClassValue>>(classes: T, propagate?: string) {
const className = joinWithLead(propagate, dehash(classes))
, host = (classes: Record<string, ClassValue>) => direct(classes, className)
, host: ClassNamingChain = classes => direct(classes, className)

host["className"] = className
stringifyClassNamed(host)
Expand Down

0 comments on commit 933a1ae

Please sign in to comment.