zag-ripple 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/machine.ripple +34 -34
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zag-ripple",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "RippleJS Adapter for Zag JS",
5
5
  "keywords": [
6
6
  "js",
@@ -108,6 +108,40 @@ export function useMachine(
108
108
 
109
109
  const refs = createRefs(machine.refs?.({ prop, context: ctx }) ?? {})
110
110
 
111
+ const send = (event) => {
112
+
113
+ if (status !== MachineStatus.Started) return
114
+
115
+ previousEventRef.current = eventRef.current
116
+ eventRef.current = event
117
+
118
+ let currentState = state.get()
119
+
120
+ const transitions =
121
+ machine.states[currentState]?.on?.[event.type] ??
122
+ machine.on?.[event.type]
123
+
124
+ const transition = choose(transitions)
125
+ if (!transition) return
126
+
127
+ // save current transition
128
+ transitionRef.current = transition
129
+ const target = transition.target ?? currentState
130
+
131
+ debug("transition", event.type, transition.target || currentState, `(${transition.actions})`)
132
+
133
+ const changed = target !== currentState
134
+ if (changed) {
135
+ state.set(target)
136
+ } else if (transition.reenter && !changed) {
137
+ // reenter will re-invoke the current state
138
+ state.invoke?.(currentState, currentState)
139
+ } else {
140
+ // call transition actions
141
+ action(transition.actions ?? [])
142
+ }
143
+ }
144
+
111
145
  const getParams = () => ({
112
146
  state: getState(),
113
147
  context: ctx,
@@ -226,40 +260,6 @@ export function useMachine(
226
260
  const initialState = machine.initialState({ prop })
227
261
  state.set(initialState)
228
262
 
229
- const send = (event) => {
230
- console.log("send", event)
231
- if (status !== MachineStatus.Started) return
232
-
233
- previousEventRef.current = eventRef.current
234
- eventRef.current = event
235
-
236
- let currentState = state.get()
237
-
238
- const transitions =
239
- machine.states[currentState]?.on?.[event.type] ??
240
- machine.on?.[event.type]
241
-
242
- const transition = choose(transitions)
243
- if (!transition) return
244
-
245
- // save current transition
246
- transitionRef.current = transition
247
- const target = transition.target ?? currentState
248
-
249
- debug("transition", event.type, transition.target || currentState, `(${transition.actions})`)
250
-
251
- const changed = target !== currentState
252
- if (changed) {
253
- state.set(target)
254
- } else if (transition.reenter && !changed) {
255
- // reenter will re-invoke the current state
256
- state.invoke?.(currentState, currentState)
257
- } else {
258
- // call transition actions
259
- action(transition.actions ?? [])
260
- }
261
- }
262
-
263
263
  machine.watch?.(getParams())
264
264
 
265
265
  return {