Skip to content

Commit

Permalink
chore: use signals
Browse files Browse the repository at this point in the history
  • Loading branch information
anubra266 committed Sep 18, 2024
1 parent f29951b commit 47824b8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
13 changes: 5 additions & 8 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, useComputed$, useStore, useVisibleTask$ } from "@builder.io/qwik"
import { NoSerialize, noSerialize, useSignal, useVisibleTask$ } from "@builder.io/qwik"
import type { Machine, StateMachine as S } from "@zag-js/core"

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

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

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

service!.start(hydratedState ?? initialState)

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

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

return useComputed$(() => store.service)
return serviceSignal
}
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, useComputed$, useSignal, useVisibleTask$ } from "@builder.io/qwik"
import { NoSerialize, noSerialize, Signal, 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 useComputed$(() => stateSignal.value)
return stateSignal
}

0 comments on commit 47824b8

Please sign in to comment.