Skip to content

Commit

Permalink
fix(types): allow partial values to create query strings
Browse files Browse the repository at this point in the history
  • Loading branch information
BowlingX committed Jan 6, 2020
1 parent 9613916 commit c079466
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/lib/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,17 @@ export const factoryParameters = <T = {}>(
const initialValues = currentState.initialValues

const createQuery = useCallback(
(values: T) => {
(values: Partial<T>) => {
return createQueryObject(flatConfig, ns, values, initialValues)
},
[initialValues]
)

return useMemo(
() => ({
createQuery: (customValues?: T) => createQuery(customValues || values),
createQueryString: (customValues?: T) =>
createQuery: (customValues?: Partial<T>) =>
createQuery(customValues || values),
createQueryString: (customValues?: Partial<T>) =>
stringify(createQuery(customValues || values)),
initialValues,
pushState: (state: (state: T) => void) => pushState(ns, state),
Expand All @@ -238,7 +239,7 @@ export const factoryParameters = <T = {}>(
)
}

const createQueryString = (values: T): string => {
const createQueryString = (values: Partial<T>): string => {
const initialValues =
typeof defaultInitialValues === 'function'
? (defaultInitialValues as () => T)()
Expand Down
2 changes: 1 addition & 1 deletion src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export const createQueriesFromPatch = <T = object>(
export const createQueryObject = <T = object>(
config: MappedConfig,
ns: string,
values: T,
values: Partial<T>,
initialState: T
) => {
return Object.keys(config).reduce((next, parameter) => {
Expand Down

0 comments on commit c079466

Please sign in to comment.