Skip to content

Commit

Permalink
chore: revert to stores
Browse files Browse the repository at this point in the history
  • Loading branch information
anubra266 committed Sep 18, 2024
1 parent fdc47af commit 7d6abca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions examples/qwik-ts/src/hooks/use-service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NoSerialize, noSerialize, useSignal, useVisibleTask$ } from "@builder.io/qwik"
import { NoSerialize, noSerialize, useComputed$, useStore, useVisibleTask$ } from "@builder.io/qwik"
import type { Machine, StateMachine as S } from "@zag-js/core"

interface UseServiceOptions<
Expand All @@ -18,7 +18,11 @@ export function useService<
const { qrl, initialState } = props
const { state: hydratedState, context } = options ?? {}

const serviceSignal = useSignal<NoSerialize<Machine<TContext, TState, TEvent>> | null>(null)
const store = useStore<{
service: NoSerialize<Machine<TContext, TState, TEvent>> | null
}>({
service: null,
})

useVisibleTask$(async ({ track, cleanup }) => {
// Load the service
Expand All @@ -31,12 +35,12 @@ export function useService<

service!.start(hydratedState ?? initialState)

serviceSignal.value = noSerialize(service)
store.service = noSerialize(service)

cleanup(() => {
service!.stop()
})
})

return serviceSignal
return useComputed$(() => store.service)
}
4 changes: 2 additions & 2 deletions examples/qwik-ts/src/hooks/use-snapshot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NoSerialize, noSerialize, Signal, useSignal, useVisibleTask$ } from "@builder.io/qwik"
import { NoSerialize, noSerialize, Signal, useComputed$, useSignal, useVisibleTask$ } from "@builder.io/qwik"
import type { Machine, StateMachine as S } from "@zag-js/core"

export function useSnapshot<
Expand Down Expand Up @@ -33,5 +33,5 @@ export function useSnapshot<
})
})

return stateSignal
return useComputed$(() => stateSignal.value)
}

0 comments on commit 7d6abca

Please sign in to comment.