greenpress / vuex-composition-helpers

A util package to use Vuex with Composition API easily.
https://www.npmjs.com/package/vuex-composition-helpers
MIT License
288 stars 32 forks source link

using Multiple Namespaced Helpers in the same component #49

Open uniquedj95 opened 2 years ago

uniquedj95 commented 2 years ago

How can I use multiple namespaced helpers in a single component?

davidmeirlevy commented 2 years ago

Use the namespaced helper twice.

uniquedj95 commented 2 years ago

will that not conflict each other. for instance,

const { useState} = createNamespacedHelper('moduleA') const { useState} = createNamespacedHelper('moduleB')

so when I call useState() which one am I calling/invoking?

davidmeirlevy commented 2 years ago

In JS you can choose between:

const { a as b } = getB() const { a as x } = getX()

Or

const a = getB().a; const b = getX().a;

Or

const mapperA = getMapper("a") const mapperB = getMapper("b") ... mappperA.useGetters(["a"])

Choose your favorite.

nolde commented 2 years ago

Would be nice to have "in-place" namespaces, similar to what happens with vuex mappers.

import { useGetters } from 'vuex-composition-helpers'

export default {
  setup() {
    const { one, two } = useGetters('my/long/name/space', ['one', 'two'])
    const { uno, dos } = useGetters('my/other/thing', ['uno', 'dos'])
    return { one, two, uno, dos }
  }
}
davidmeirlevy commented 2 years ago

@nolde as you can see in the source code, the global functions are passing null as a namespace to the useMapping function.

If you like to create an improvement that will pass the namespace to the global functions, you're welcome, just make sure all the tests will pass :)