Skip to content

Commit afdf78c

Browse files
committed
chore: update plop template
1 parent 962a6ba commit afdf78c

4 files changed

+44
-41
lines changed

plop/machine/src/{{machine}}.connect.ts.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { State, Send } from "./{{dashCase machine}}.types"
33
import { parts } from "./{{dashCase machine}}.anatomy"
44
import { dom } from "./{{dashCase machine}}.dom"
55

6-
export function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>) {
6+
export function connect<T extends PropTypes>(service: {{machine}}Service, normalize: NormalizeProps<T>) {
77
return {
88
getRootProps() {
99
return normalize.element({})
+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { createScope } from "@zag-js/dom-query"
2-
import type { MachineContext as Ctx } from "./{{dashCase machine}}.types"
1+
import type { Scope } from "@zag-js/core"
32

4-
export const dom = createScope({})
3+
export const getRootId = (ctx: MachineContext) => `{{dashCase machine}}-${ctx.id}`
+29-23
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
1-
import { createMachine, ref } from "@zag-js/core"
2-
import { compact } from "@zag-js/utils"
3-
import type { MachineContext, MachineState, UserDefinedContext } from "./{{dashCase machine}}.types"
1+
import { createMachine } from "@zag-js/core"
2+
import type { {{machine}}Schema } from "./{{dashCase machine}}.types"
43

5-
export function machine(userContext: UserDefinedContext){
6-
const ctx = compact(userContext)
7-
return createMachine<MachineContext, MachineState>(
8-
{
9-
id: "{{machine}}",
10-
initial: "idle",
11-
context: {
12-
...ctx
13-
},
14-
states: {
15-
},
16-
},
17-
{
18-
guards: {
19-
},
20-
actions: {
21-
},
22-
},
23-
)
24-
}
4+
export const machine = createMachine<{{machine}}Schema>({
5+
props({ props }) {
6+
return props
7+
},
8+
9+
context({ props, bindable }) {
10+
return {}
11+
},
12+
13+
initialState() {
14+
return "idle"
15+
},
16+
17+
context({ props }) {
18+
return props
19+
},
20+
21+
states: {},
22+
23+
implementations: {
24+
guards: {},
25+
26+
actions: {},
27+
28+
effects: {},
29+
}
30+
})
+12-14
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
import type { StateMachine as S } from "@zag-js/core"
1+
import type { EventObject, Service, Machine } from "@zag-js/core"
22
import type { CommonProperties, DirectionProperty, RequiredBy } from "@zag-js/types"
33

4-
interface PublicContext extends DirectionProperty, CommonProperties {}
4+
export interface {{machine}}Props extends DirectionProperty, CommonProperties {}
55

6-
interface PrivateContext extends {}
7-
8-
type ComputedContext = Readonly<{}>
9-
10-
export type UserDefinedContext = RequiredBy<PublicContext, "id">
11-
12-
export interface MachineContext extends PublicContext, PrivateContext, ComputedContext {}
13-
14-
export interface MachineState {
15-
value: "idle"
6+
export interface {{machine}}Schema {
7+
state: 'idle'
8+
props: {{machine}}Props
9+
context: {}
10+
event: EventObject
11+
action: string
12+
guard: string
13+
effect: string
1614
}
1715

18-
export type State = S.State<MachineContext, MachineState>
16+
export type {{machine}}Service = Service<{{machine}}Schema>
1917

20-
export type Send = S.Send<S.AnyEventObject>
18+
export type {{machine}}Machine = Machine<{{machine}}Schema>

0 commit comments

Comments
 (0)