-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion for modifying the use functions #50
Comments
Interesting idea. But you suggest it to work for inside the namespaced helper only? Would you like to contribute this feature? Make sure it must have backwards comparability. |
sure, I was thinking for all helpers. |
@davidmeirlevy ok so I have a working prototype. Using useState as an example export function useState(storeOrMap, map) {
let store = storeOrMap;
if (isArray(store)) {
map = store;
store = getStoreFromInstance();
}
else if (isString(store)) {
map = Array.from(arguments);
store = getStoreFromInstance();
}
return useMapping(store, null, map, computedState);
} This works in terms of javascript, however there is an issue with the typescript. export function useState<TState>(map: KnownKeys<TState>[]): RefTypes<TState>
export function useState<TState>(...keys: KnownKeys<TState>[]): RefTypes<TState>
// ^^^^^^^^^^^^^^^^^^^^ `This overload signature is not compatible with its implementation signature.ts(2394)`
export function useState<TState>(store: Store<TState>, map: KnownKeys<TState>[]): RefTypes<TState>
export function useState<TState = any>(storeOrMap: Store<TState> | KnownKeys<TState>[], map?: KnownKeys<TState>[]): RefTypes<TState> {
...
}
If the helpers could instead be partially applied I have cleaned up some of the code changes I made in the process though and I can make a PR with those changes. |
Typescript integration is the hardest issue over here, I know. Maybe this function should have several different signatures in order to work. I would go for this type of solution. |
You could change this line and all similar use functions from:
vuex-composition-helpers/src/namespaced.ts
Line 84 in 1af7716
To be
which would eliminate the need to explicitly pass the map in as an array:
The text was updated successfully, but these errors were encountered: