Skip to content

Conversation

@teleskop150750
Copy link

@teleskop150750 teleskop150750 commented Apr 3, 2025

Refactor shallow function
for replaced with for-of

Drop Vue 2 support, optimize bundles and clean up

Use shallowRef
There is no point in using ref with deep reactivity because the entire object is replaced.

An alternative might be to create a solidjs reconcile analogue for vue
Link

Use MaybeRefOrGetter
to be able to pass reactive variables

Required for tantack db to work
TanStack/db#85

Instead of watchEffect you can use computed, but this will change the type of the returned result
Example

export function useStore<TState, TSelected = NoInfer<TState>>(
  store: MaybeRefOrGetter<Store<TState, any>>,
  selector?: (state: NoInfer<TState>) => TSelected,
): () => TSelected
export function useStore<TState, TSelected = NoInfer<TState>>(
  store: MaybeRefOrGetter<Derived<TState, any>>,
  selector?: (state: NoInfer<TState>) => TSelected,
): () => TSelected
export function useStore<TState, TSelected = NoInfer<TState>>(
  store: MaybeRefOrGetter<Store<TState, any> | Derived<TState, any>>,
  selector: (state: NoInfer<TState>) => TSelected = (d) => d as any,
): () => TSelected {
  let unsub = () => {}
  const data = computed(() => {
    const storeValue = toValue(store)
    let sliceRef = selector(storeValue.state)
    const slice = shallowRef(sliceRef)

    unsub()
    unsub = storeValue.subscribe(() => {
      const newValue = selector(storeValue.state)
      if (shallow(sliceRef, newValue)) return

      sliceRef = newValue
      slice.value = newValue
    })
    return slice
  })

  return () => data.value.value
}

@teleskop150750 teleskop150750 changed the title feat: drop vue 2 support feat: drop vue 2 support and refactor May 19, 2025
@teleskop150750 teleskop150750 changed the title feat: drop vue 2 support and refactor feat: drop vue 2 support and allow dynamic Store instance May 19, 2025
@teleskop150750 teleskop150750 changed the title feat: drop vue 2 support and allow dynamic Store instance feat(vue): drop vue 2 support and allow dynamic Store instance May 19, 2025
@crutchcorn
Copy link
Member

Please provide a description of what you're doing and why, alongside rationale for your changes. Closing until then.

@crutchcorn crutchcorn closed this May 23, 2025
@teleskop150750
Copy link
Author

@crutchcorn Added description

@teleskop150750
Copy link
Author

@crutchcorn Hi, can you open this PR? 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants