Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
192 commits
Select commit Hold shift + click to select a range
8cc9b72
feat(alpine): create alpine-ts example
niLPotential Nov 19, 2025
7370f62
chore: add example deps
niLPotential Nov 19, 2025
ebe6797
chore: add Head component
niLPotential Nov 19, 2025
421ada1
feat(alpine): add lib files
niLPotential Nov 19, 2025
fb94ac1
feat(alpine): add Nav component
niLPotential Nov 19, 2025
e7c0654
feat(alpine): add style script
niLPotential Nov 19, 2025
79d3900
feat(alpine): add deps
niLPotential Nov 19, 2025
84c59be
chore: add lucide static
niLPotential Nov 19, 2025
c2107f2
feat(alpine): add accordion example
niLPotential Nov 19, 2025
f53cdb9
feat(alpine): add alpine scripts
niLPotential Nov 20, 2025
c10c71f
feat(alpine): add toolbar components
niLPotential Nov 20, 2025
3ca58cc
feat(alpine): finish accordion example
niLPotential Nov 20, 2025
9c138fd
feat(alpine): add angle slider example
niLPotential Nov 20, 2025
067d5a3
feat(alpine): add avatar example
niLPotential Nov 20, 2025
6912c62
feat(alpine): add presence component
niLPotential Nov 20, 2025
1565187
feat(alpine): add checkbox example
niLPotential Nov 20, 2025
8df8ff3
feat(alpine): add switch example
niLPotential Nov 20, 2025
a4887c1
feat(alpine): add editable example
niLPotential Nov 20, 2025
2facb02
feat(alpine): add number input example
niLPotential Nov 21, 2025
bebca40
feat(alpine): add rating group example
niLPotential Nov 21, 2025
7c164cb
feat(alpine): add hover card example
niLPotential Nov 21, 2025
fd6cc89
feat(alpine): add tags input example
niLPotential Nov 21, 2025
225d999
feat(alpine): add clipboard example
niLPotential Nov 21, 2025
264a1ca
feat(alpine): add password input example
niLPotential Nov 21, 2025
9c96a23
fix: import icons as magic
niLPotential Nov 21, 2025
08e99b3
feat(alpine): add pin input example
niLPotential Nov 21, 2025
3bc49cf
feat(alpine): add color picker example
niLPotential Nov 21, 2025
bab0539
feat(alpine): add pagination example
niLPotential Nov 21, 2025
1342317
feat(alpine): add radio group example
niLPotential Nov 21, 2025
59549d7
feat(alpine): add select example
niLPotential Nov 21, 2025
f99a185
feat(alpine): add slider example
niLPotential Nov 21, 2025
dd06fcd
feat(alpine): add tooltip example
niLPotential Nov 21, 2025
5828ea0
feat(alpine): add tabs example
niLPotential Nov 21, 2025
c5841b8
feat(alpine): add toggle example
niLPotential Nov 22, 2025
4c26e1f
feat(alpine): add toggle group example
niLPotential Nov 22, 2025
0f128b9
feat(alpine): add timer examples
niLPotential Nov 22, 2025
409515f
feat(alpine): add steps example
niLPotential Nov 22, 2025
f6a3e21
fix: simplify magics
niLPotential Nov 22, 2025
aabb781
feat(alpine): add scroll area example
niLPotential Nov 22, 2025
c3717d2
feat(alpine): add progress example
niLPotential Nov 22, 2025
18598e6
chore: remove default files
niLPotential Nov 22, 2025
52637fa
fix: add index page
niLPotential Nov 22, 2025
f9382a8
Merge branch 'main' into alpine-ts
niLPotential Nov 22, 2025
0008479
feat(alpine): add dialog examples
niLPotential Nov 22, 2025
49c5e64
feat(alpine): add floating panel example
niLPotential Nov 22, 2025
6d81212
feat(alpine): add controlled checkbox example
niLPotential Nov 22, 2025
5c0ef12
feat(alpine): add range slider example
niLPotential Nov 22, 2025
bf73bbc
fix: handle multiple instances with modifier
niLPotential Nov 23, 2025
e3a6abc
fix: call api magic
niLPotential Nov 23, 2025
d4f5a3a
feat(alpine): add segment control example
niLPotential Nov 23, 2025
37ff543
feat(alpine): add qr code example
niLPotential Nov 23, 2025
040dee1
feat(alpine): add bottom-sheet example
niLPotential Nov 24, 2025
00e8d20
feat(alpine): add carousel examples
niLPotential Nov 25, 2025
37a2925
feat(alpine): add combobox examples
niLPotential Nov 27, 2025
0269696
feat(alpine): add listbox examples
niLPotential Nov 27, 2025
fadadba
feat(alpine): add presence example
niLPotential Nov 28, 2025
af1c9b4
feat(alpine): add file upload example
niLPotential Nov 28, 2025
74a7bd9
feat(alpine): add marquee example
niLPotential Nov 28, 2025
cc9586f
feat(alpine): add popper example
niLPotential Nov 28, 2025
3f56c3f
feat(alpine): add autoresize example
niLPotential Nov 28, 2025
d9dc00f
feat(alpine): add async list example
niLPotential Nov 28, 2025
1f0569c
Merge branch 'main' into alpine-ts
niLPotential Nov 29, 2025
2e65f78
feat(alpine): add menu examples
niLPotential Nov 29, 2025
6610d93
feat(alpine): add context menu examples
niLPotential Nov 29, 2025
f14c390
Merge branch 'alpine-ts' into update
niLPotential Feb 17, 2026
4a16682
Merge pull request #4 from niLPotential/update
niLPotential Feb 17, 2026
048aca4
Merge branch 'chakra-ui:main' into alpine-ts
niLPotential Mar 5, 2026
f702075
chore: update deps
niLPotential Mar 5, 2026
86f7165
refactor: bottom sheet -> drawer
niLPotential Mar 5, 2026
e4a1f88
chore: update vite
niLPotential Mar 6, 2026
5e41dbe
fix: use relative imports
niLPotential Mar 6, 2026
093e1d6
refactor: examples
niLPotential Mar 6, 2026
def0f70
refactor: rm match-sorter
niLPotential Mar 6, 2026
389a753
refactor: follow vanilla package
niLPotential Mar 6, 2026
3614d6d
refactor: useEvaluator
niLPotential Mar 6, 2026
4d098ed
refactor: usePartProps
niLPotential Mar 6, 2026
8b53c26
fix: update combobox example
niLPotential Mar 6, 2026
5f8b695
fix: mutateDom when state changes
niLPotential Mar 7, 2026
4aec6cf
fix: simplify binding
niLPotential Mar 7, 2026
f1146ed
Merge branch 'chakra-ui:main' into alpine-ts
niLPotential Mar 7, 2026
35d2776
chore: update deps
niLPotential Mar 7, 2026
7e206f2
refactor: current component as middleware
niLPotential Mar 7, 2026
808c258
refactor: componentRoutesData
niLPotential Mar 7, 2026
06c8ea5
fix: title
niLPotential Mar 7, 2026
6492b35
refactor: add dynamic component route
niLPotential Mar 7, 2026
cf1596c
refactor: nav currentComponent
niLPotential Mar 7, 2026
59ff3cb
fix: magic casing
niLPotential Mar 7, 2026
b1f8913
fix: handle transformed control values
niLPotential Mar 7, 2026
9fd7bc1
refactor: useData
niLPotential Mar 7, 2026
d71c137
fix: remove path
niLPotential Mar 7, 2026
c06fff7
fix: import
niLPotential Mar 7, 2026
6e59274
fix: hidden input
niLPotential Mar 7, 2026
09ef922
refactor: useData
niLPotential Mar 7, 2026
de786d2
fix: decrease use of queueMicrotask
niLPotential Mar 7, 2026
2be5208
refactor: handle props normalization in binding
niLPotential Mar 8, 2026
673882b
feat(alpine): menu examples with e2e
niLPotential Mar 8, 2026
9b778f6
feat(alpine): navigation menu
niLPotential Mar 9, 2026
dc1e5c9
feat(alpine): listbox
niLPotential Mar 9, 2026
beed48f
feat(alpine): password input
niLPotential Mar 9, 2026
2a4fda5
feat(alpine): pin input
niLPotential Mar 9, 2026
b5bd7cf
feat(alpine): radio group
niLPotential Mar 9, 2026
442dccb
feat(alpine): rating group
niLPotential Mar 9, 2026
32cbe30
feat(alpine): switch
niLPotential Mar 9, 2026
76a1075
Merge branch 'chakra-ui:main' into alpine-ts
niLPotential Mar 9, 2026
b9b1c3e
feat(alpine): tabs
niLPotential Mar 9, 2026
7f689c6
feat(alpine): toggle group
niLPotential Mar 9, 2026
2278d37
feat(alpine): slider
niLPotential Mar 9, 2026
e8a271d
feat(alpine): tags input
niLPotential Mar 9, 2026
c5ecb66
feat(alpine): pagination
niLPotential Mar 10, 2026
91914e7
refactor: useData -> useControls
niLPotential Mar 10, 2026
d55aa94
feat(alpine): splitter
niLPotential Mar 10, 2026
febfb98
feat(alpine): floating panel
niLPotential Mar 10, 2026
61cdfe2
feat(alpine): popover
niLPotential Mar 10, 2026
46d0557
feat(alpine): date input wip
niLPotential Mar 10, 2026
5e5f530
refactor: drawer wip
niLPotential Mar 10, 2026
b90bae0
feat(alpine): image cropper
niLPotential Mar 11, 2026
347f900
fix: event handler could be undefined
niLPotential Mar 11, 2026
4989896
feat(alpine): date picker wip
niLPotential Mar 11, 2026
4384935
fix: x-for key values
niLPotential Mar 11, 2026
6cb5cde
feat(alpine): select wip
niLPotential Mar 11, 2026
d23450e
fix: handle undefined refs
niLPotential Mar 11, 2026
9962707
feat(alpine): tour
niLPotential Mar 11, 2026
3eb971f
fix: revert bindable set fn
niLPotential Mar 11, 2026
6880139
Merge branch 'chakra-ui:main' into alpine-ts
niLPotential Mar 11, 2026
42c7006
Merge branch 'chakra-ui:main' into alpine-ts
niLPotential Mar 13, 2026
2012174
refactor: let Alpine handle deps change
niLPotential Mar 15, 2026
d7b7591
fix: better types for useEvaluator
niLPotential Mar 15, 2026
9740980
refactor: effect -> x-effect
niLPotential Mar 15, 2026
8afdee5
chore: vite beta -> latest
niLPotential Mar 16, 2026
563d9c0
Merge branch 'chakra-ui:main' into alpine-ts
niLPotential Mar 16, 2026
a9384d1
refactor: cache user props with effect
niLPotential Mar 16, 2026
f44d70b
refactor: queueMicrotask init
niLPotential Mar 16, 2026
8d8f9ee
fix: controls slot
niLPotential Mar 16, 2026
af85259
fix: segment key
niLPotential Mar 16, 2026
63f7499
fix: add date controls
niLPotential Mar 16, 2026
beed317
fix: revert(2012174) deep check deps
niLPotential Mar 17, 2026
2370043
fix: segment index
niLPotential Mar 17, 2026
e63f3dd
fix: type number controls
niLPotential Mar 17, 2026
ca1142d
fix: seperate controls data
niLPotential Mar 17, 2026
d945c41
fix: pass present as prop
niLPotential Mar 17, 2026
a7ff367
refactor: get hidden in presence
niLPotential Mar 17, 2026
4f3b0a2
feat(alpine): drawer
niLPotential Mar 17, 2026
c82137a
fix: pass present from parent api
niLPotential Mar 17, 2026
ee720f2
feat(alpine): drawer indent
niLPotential Mar 17, 2026
fe8b775
feat(alpine): combobox
niLPotential Mar 17, 2026
57cacb7
refactor: handle collection with effect
niLPotential Mar 17, 2026
1e77483
Merge branch 'chakra-ui:main' into alpine-ts
niLPotential Mar 17, 2026
f586c15
Merge branch 'alpine-ts' into temp
niLPotential May 26, 2026
6a7e47e
Merge pull request #5 from niLPotential/temp
niLPotential May 26, 2026
62bc9f3
chore: update deps
niLPotential May 27, 2026
a3e3685
fix: drawer snap points
niLPotential May 27, 2026
795adfd
refactor: rename indent example
niLPotential May 27, 2026
992d90c
refactor: seperate drawer indent script
niLPotential May 27, 2026
68919c1
Merge branch 'alpine-ts' into temp
niLPotential Jun 23, 2026
42539eb
Merge pull request #6 from niLPotential/temp
niLPotential Jun 23, 2026
9535e71
chore: update deps
niLPotential Jun 23, 2026
a68ab54
feat(alpine): context-menu/multiple-trigger
niLPotential Jun 23, 2026
2485b57
feat(alpine): dialog/multiple-trigger
niLPotential Jun 23, 2026
9ffc146
feat(alpine): pin-input/controlled
niLPotential Jun 23, 2026
20b367a
feat(alpine): pin-input/transform-paste
niLPotential Jun 23, 2026
33786e4
feat(alpine): hover-card/multiple-trigger
niLPotential Jun 23, 2026
4b94c81
feat(alpine): menu/multiple-trigger
niLPotential Jun 23, 2026
cfa96c5
feat(alpine): popover/single-tab-stop
niLPotential Jun 23, 2026
3553763
feat(alpine): popover/multiple-trigger
niLPotential Jun 23, 2026
129b074
fix: typo
niLPotential Jun 23, 2026
1007a36
refactor: bind > object from entries
niLPotential Jun 24, 2026
41b3966
fix: declare alpine port
niLPotential Jun 25, 2026
97e9067
feat(alpine): toast wip
niLPotential Jun 25, 2026
d7622b6
fix: single child inside template
niLPotential Jun 25, 2026
8a31566
fix: remove types
niLPotential Jun 25, 2026
39cf40e
fix: handle JSX
niLPotential Jun 25, 2026
679e878
fix: no data declaration in between
niLPotential Jun 25, 2026
05890b2
feat(alpine): tooltip/multiple-trigger
niLPotential Jun 25, 2026
837e409
feat(alpine): date-input routes
niLPotential Jun 25, 2026
db82fe8
fix: controls slot
niLPotential Jun 25, 2026
a05f714
feat(alpine): drawer/swipe-area
niLPotential Jun 25, 2026
e8b8686
feat(alpine): combobox/form
niLPotential Jun 25, 2026
9b2b708
fix: watch object of deps
niLPotential Jun 25, 2026
78e4cdd
fix: queueMicrotask transition and entering actions
niLPotential Jun 26, 2026
6da566a
refactor: part props evaluation
niLPotential Jun 26, 2026
8685125
refactor: expose service as magic
niLPotential Jun 26, 2026
18b540d
refactor: move use-controls to /scripts
niLPotential Jun 26, 2026
f872ed2
fix: service in state visualizer
niLPotential Jun 26, 2026
a435ecf
refactor: intergrate service into api magic
niLPotential Jun 26, 2026
b967757
chore: tidy up
niLPotential Jun 26, 2026
8dea3ac
fix: drawer/indent-effect
niLPotential Jun 26, 2026
7013d39
Merge branch 'chakra-ui:main' into alpine-ts
niLPotential Jun 27, 2026
a0189dd
feat(alpine): tags-input/form
niLPotential Jun 27, 2026
5daf5f8
refactor: simplify binding
niLPotential Jun 27, 2026
de32649
Merge branch 'chakra-ui:main' into alpine-ts
niLPotential Jun 29, 2026
c92d8a0
Merge branch 'alpine-ts' of https://github.com/niLPotential/zag into …
niLPotential Jun 29, 2026
c5fe6f7
feat(alpine-ts): date-picker/custom-calendar
niLPotential Jun 29, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions examples/alpine-ts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
dist
.data
.nitro
.cache
.output
.env
.env.local
19 changes: 19 additions & 0 deletions examples/alpine-ts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Nitro starter

Create your full-stack apps and deploy it anywhere with this [Vite](https://vite.dev/) + [Nitro](https://v3.nitro.build/) starter.

## Getting started

```bash
npm install
npm run dev
```

## Deploying

```bash
npm run build
npm run preview
```

Then checkout the [Nitro documentation](https://v3.nitro.build/deploy) to learn more about the different deployment presets.
58 changes: 58 additions & 0 deletions examples/alpine-ts/lib/bindable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import type { Bindable, BindableParams } from "@zag-js/core"
import { isFunction } from "@zag-js/utils"
import Alpine from "alpinejs"

export function bindable<T>(props: () => BindableParams<T>): Bindable<T> {
const initial = props().value ?? props().defaultValue

if (props().debug) {
console.log(`[bindable > ${props().debug}] initial`, initial)
}

const eq = props().isEqual ?? Object.is

const store = Alpine.reactive({ value: initial as T })

const controlled = () => props().value !== undefined

return {
initial,
ref: store,
get() {
return controlled() ? (props().value as T) : store.value
},
set(nextValue: T | ((prev: T) => T)) {
const prev = store.value
const next = isFunction(nextValue) ? nextValue(prev) : nextValue

if (props().debug) {
console.log(`[bindable > ${props().debug}] setValue`, { next, prev })
}

if (!controlled()) store.value = next
if (!eq(next, prev)) {
props().onChange?.(next, prev)
}
},
invoke(nextValue: T, prevValue: T) {
props().onChange?.(nextValue, prevValue)
},
hash(value: T) {
return props().hash?.(value) ?? String(value)
},
}
}

bindable.cleanup = (_fn: VoidFunction) => {
// Alpine.onElRemoved(() => fn())
}

bindable.ref = <T>(defaultValue: T) => {
let value = defaultValue
return {
get: () => value,
set: (next: T) => {
value = next
},
}
}
1 change: 1 addition & 0 deletions examples/alpine-ts/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { usePlugin } from "./plugin"
306 changes: 306 additions & 0 deletions examples/alpine-ts/lib/machine.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,306 @@
import type {
ActionsOrFn,
Bindable,
BindableContext,
BindableRefs,
ChooseFn,
ComputedFn,
EffectsOrFn,
GuardFn,
Machine,
MachineSchema,
Params,
PropFn,
Scope,
Service,
Transition,
} from "@zag-js/core"
import {
createScope,
findTransition,
getExitEnterStates,
hasTag,
INIT_STATE,
MachineStatus,
matchesState,
resolveStateValue,
} from "@zag-js/core"
import { compact, isFunction, isString, runIfFn, toArray, warn } from "@zag-js/utils"
import { bindable } from "./bindable"
import { createRefs } from "./refs"
import { track } from "./track"

export class AlpineMachine<T extends MachineSchema> {
scope: Scope
context: BindableContext<T>
prop: PropFn<T>
state: Bindable<T["state"]>
refs: BindableRefs<T>
computed: ComputedFn<T>

private event: T["event"] = { type: "" }
private previousEvent: T["event"] = { type: "" }

private effects = new Map<string, VoidFunction>()
private transition: Transition<T> | null = null

private getEvent = () => ({
...this.event,
current: () => this.event,
previous: () => this.previousEvent,
})

private getState = () => ({
...this.state,
matches: (...values: T["state"][]) =>
values.some((value) => matchesState(this.state.get() as string, value as string)),
hasTag: (tag: T["tag"]) => hasTag(this.machine, this.state.get(), tag),
})

private debug = (...args: any[]) => {
if (this.machine.debug) console.log(...args)
}

constructor(
private machine: Machine<T>,
userPropsRef: { value: Partial<T["props"]> | (() => Partial<T["props"]>) },
) {
// create scope
const { id, ids, getRootNode } = runIfFn(userPropsRef.value) as any
this.scope = createScope({ id, ids, getRootNode })

// create prop
const prop: PropFn<T> = (key) => {
const __props = runIfFn(userPropsRef.value)
const props = machine.props?.({ props: compact(__props), scope: this.scope }) ?? __props
return props[key]
}
this.prop = prop

// create context
const context = machine.context?.({
prop,
bindable,
scope: this.scope,
flush,
getContext() {
return ctx
},
getComputed() {
return computed
},
getRefs() {
return refs
},
getEvent: this.getEvent.bind(this),
})

// context function
const ctx: BindableContext<T> = {
get(key) {
return context?.[key].get() as T["context"][typeof key]
},
set(key, value) {
context?.[key].set(value)
},
initial(key) {
return context?.[key].initial as T["context"][typeof key]
},
hash(key) {
const current = context?.[key].get() as T["context"][typeof key]
return context?.[key].hash(current) as string
},
}
this.context = ctx

const computed: ComputedFn<T> = (key) => {
return machine.computed?.[key]({
context: ctx,
event: this.getEvent(),
prop,
refs: this.refs,
scope: this.scope,
computed,
}) as T["computed"][typeof key]
}
this.computed = computed

const refs: BindableRefs<T> = createRefs(machine.refs?.({ prop, context: ctx }) ?? {})
this.refs = refs

// state
const state = bindable(() => ({
defaultValue: resolveStateValue(machine, machine.initialState({ prop })),
onChange: (nextState, prevState) => {
const { exiting, entering } = getExitEnterStates(this.machine, prevState, nextState, this.transition?.reenter)

exiting.forEach((item) => {
const exitEffects = this.effects.get(item.path)
exitEffects?.()
this.effects.delete(item.path)
})

exiting.forEach((item) => {
this.action(item.state?.exit)
})

queueMicrotask(() => {
this.action(this.transition?.actions)

entering.forEach((item) => {
const cleanup = this.effect(item.state?.effects)
if (cleanup) this.effects.set(item.path, cleanup)
})

if (prevState === INIT_STATE) {
this.action(machine.entry)
const cleanup = this.effect(machine.effects)
if (cleanup) this.effects.set(INIT_STATE, cleanup)
}

entering.forEach((item) => {
this.action(item.state.entry)
})
})
},
}))
this.state = state
}

send = (event: T["event"]) => {
if (this.status !== MachineStatus.Started) return

if (!event) return

this.previousEvent = this.event
this.event = event

this.debug("send", event)

let currentState = this.state.get()

const eventType = event.type
const { transitions, source } = findTransition(this.machine, currentState, eventType)
const transition = this.choose(transitions)
if (!transition) return

// save current transition
this.transition = transition
const target = resolveStateValue(this.machine, transition.target ?? currentState, source)

this.debug("transition", transition)

const changed = target !== currentState
if (changed) {
// state change is high priority
this.state.set(target)
} else if (transition.reenter) {
// reenter will re-invoke the current state
this.state.invoke(currentState, currentState)
} else {
// call transition actions
this.action(transition.actions)
}
}

private action = (keys: ActionsOrFn<T> | undefined) => {
const strs = isFunction(keys) ? keys(this.getParams()) : keys
if (!strs) return
const fns = strs.map((s) => {
const fn = this.machine.implementations?.actions?.[s]
if (!fn) warn(`[zag-js] No implementation found for action "${JSON.stringify(s)}"`)
return fn
})
for (const fn of fns) {
fn?.(this.getParams())
}
}

private guard = (str: T["guard"] | GuardFn<T>) => {
if (isFunction(str)) return str(this.getParams())
return this.machine.implementations?.guards?.[str](this.getParams())
}

private effect = (keys: EffectsOrFn<T> | undefined) => {
const strs = isFunction(keys) ? keys(this.getParams()) : keys
if (!strs) return
const fns = strs.map((s) => {
const fn = this.machine.implementations?.effects?.[s]
if (!fn) warn(`[zag-js] No implementation found for effect "${JSON.stringify(s)}"`)
return fn
})
const cleanups: VoidFunction[] = []
for (const fn of fns) {
const cleanup = fn?.(this.getParams())
if (cleanup) cleanups.push(cleanup)
}
return () => cleanups.forEach((fn) => fn?.())
}

private choose: ChooseFn<T> = (transitions) => {
return toArray(transitions).find((t) => {
let result = !t.guard
if (isString(t.guard)) result = !!this.guard(t.guard)
else if (isFunction(t.guard)) result = t.guard(this.getParams())
return result
})
}

init() {
this.status = MachineStatus.Started
this.debug("initializing...")
queueMicrotask(() => {
this.state.invoke(this.state.initial!, INIT_STATE)
})
this.machine.watch?.(this.getParams())
}

destroy() {
// run exit effects
this.effects.forEach((fn) => fn?.())
this.effects.clear()
this.transition = null
this.action(this.machine.exit)

this.status = MachineStatus.Stopped
this.debug("unmounting...")
}

private status = MachineStatus.NotStarted

get service() {
return {
state: this.getState(),
send: this.send,
context: this.context,
prop: this.prop,
scope: this.scope,
refs: this.refs,
computed: this.computed,
event: this.getEvent(),
getStatus: () => this.status,
} as Service<T>
}

getParams = () =>
({
state: this.getState(),
context: this.context,
event: this.getEvent(),
prop: this.prop,
send: this.send,
action: this.action,
guard: this.guard,
track,
refs: this.refs,
computed: this.computed,
flush,
scope: this.scope,
choose: this.choose,
}) as Params<T>
}

function flush(fn: VoidFunction) {
console.log("flush")
fn()
}
Loading