Skip to content

Commit

Permalink
fix(useReactive, createSingleLoading): use require to dynamic import …
Browse files Browse the repository at this point in the history
…to avoid no dep error
  • Loading branch information
vikiboss committed Jul 2, 2024
1 parent 7a108bd commit fc9d1ee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/create-single-loading/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { create } from '@shined/reactive'
import { useAsyncFn as useAsyncFnOrigin } from '../use-async-fn'

import type { create } from '@shined/reactive'
import type { UseAsyncFnReturns } from '../use-async-fn'
import type { AnyFunc } from '../utils/basic'

Expand Down Expand Up @@ -77,7 +77,9 @@ export interface CreateSingleLoadingOptions {
*/
export function createSingleLoading(options: CreateSingleLoadingOptions = {}): CreateSingleLoadingReturns {
const { resetOnError = true, initialState = false } = options
const store = create({ loading: initialState })

const createStore = require('@shined/reactive').create as typeof create
const store = createStore({ loading: initialState })

function bind<T extends AnyFunc>(func: T): T {
return (async (...args: Parameters<T>) => {
Expand Down
9 changes: 7 additions & 2 deletions src/use-reactive/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { create } from '@shined/reactive'
import { useCreation } from '../use-creation'

import type { create } from '@shined/reactive'

// TODO: export from @shined/reactive
interface SnapshotOptions<StateSlice> {
sync?: boolean
Expand All @@ -19,6 +20,10 @@ export function useReactive<State extends object>(
initialState: State,
options: SnapshotOptions<State> = {},
): readonly [State, State] {
const store = useCreation(() => create(initialState))
const store = useCreation(() => {
const createStore = require('@shined/reactive').create as typeof create
return createStore(initialState)
})

return [store.useSnapshot(options), store.mutate] as const
}

0 comments on commit fc9d1ee

Please sign in to comment.