Skip to content

Commit

Permalink
chore: update plop templates
Browse files Browse the repository at this point in the history
  • Loading branch information
segunadebayo committed Oct 15, 2021
1 parent d711d3c commit c32502f
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 18 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
coverage
.next
build
*.hbs
11 changes: 9 additions & 2 deletions plop-templates/machine-template/index.ts.hbs
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
export * from "./{{machine}}.connect"
export * from "./{{machine}}.machine"
import { {{machine}}Connect } from "./{{machine}}.connect"
import { {{machine}}Machine } from "./{{machine}}.machine"

export const {{machine}} = {
machine: {{machine}}Machine,
connect: {{machine}}Connect,
}

export type { {{capitalize machine}}MachineContext, {{capitalize machine}}MachineState } from "./{{machine}}.types"
17 changes: 5 additions & 12 deletions plop-templates/machine-template/{{machine}}.connect.ts.hbs
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import {
defaultPropNormalizer,
PropNormalizer,
StateMachine as S,
} from "@ui-machines/core"
import { Props } from "../type-utils"
import { defaultPropNormalizer, getEventKey } from "../utils"
import type { DOM, Props } from "../utils"
import { getIds, getElements } from "./{{machine}}.dom"
import { {{capitalize machine}}MachineContext, {{capitalize machine}}MachineState } from "./{{machine}}.machine"

export function connect{{capitalize machine}}Machine(
state: S.State<{{capitalize machine}}MachineContext, {{capitalize machine}}MachineState>,
send: (event: S.Event<S.AnyEventObject>) => void,
export function connect{{capitalize machine}}(
state: {{capitalize machine}}State,
send: {{capitalize machine}}Send,
normalize = defaultPropNormalizer,
) {
const { context: ctx } = state
const ids = getIds(ctx.uid)

return {
elProps: normalize<Props.Element>({
}),
Expand Down
10 changes: 6 additions & 4 deletions plop-templates/machine-template/{{machine}}.dom.ts.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {
{{capitalize machine}}MachineContext } from "./{{machine}}.machine" export function getIds(uid: string) { return { } }
export function getElements(ctx:
{{capitalize machine}}MachineContext) { const doc = ctx.doc ?? document const ids = getIds(ctx.uid) return { } }
import type { {{capitalize machine}}MachineContext as Ctx } from "./{{machine}}.types"

export const dom = {
getDoc: (ctx: Ctx) => ctx.doc ?? document,
getRootId: (ctx: Ctx) => `{{machine}}-${ctx.uid}`,
}
1 change: 1 addition & 0 deletions plop-templates/machine-template/{{machine}}.machine.ts.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createMachine, preserve } from "@ui-machines/core"
import { Context } from "../type-utils"
import { {{capitalize machine}}MachineContext, {{capitalize machine}}MachineState } from "./{{machine}}.types"

export type {{capitalize machine}}MachineContext = Context<{}>

Expand Down
18 changes: 18 additions & 0 deletions plop-templates/machine-template/{{machine}}.types.ts.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { StateMachine as S } from "@ui-machines/core"
import type { Context } from "../utils"

export type {{capitalize machine}}MachineContext = Context<{
}>

export type {{capitalize machine}}MachineState = {
value: "unknown" | "idle" | "focused"
}

export type {{capitalize machine}}State = S.State<{{capitalize machine}}MachineContext, {{capitalize machine}}MachineState>

export type {{capitalize machine}}Send = S.Send<S.AnyEventObject>

export type {{capitalize machine}}ItemProps = {
value: string
disabled?: boolean
}

0 comments on commit c32502f

Please sign in to comment.