Skip to content

Commit

Permalink
state > stateParams
Browse files Browse the repository at this point in the history
  • Loading branch information
stackoverfloweth committed Aug 16, 2024
1 parent 5299f06 commit c1cf6e9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/services/createRoute.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ test('given parent, query is combined', () => {
})
})

test('given parent, state is combined into stateParams', () => {
test('given parent, state is combined into state', () => {
const parent = createRoute({
state: {
foo: Number,
Expand All @@ -66,7 +66,7 @@ test('given parent, state is combined into stateParams', () => {
},
})

expect(child.stateParams).toMatchObject({
expect(child.state).toMatchObject({
foo: Number,
bar: String,
})
Expand All @@ -83,7 +83,7 @@ test('given parent and child without state, state matches parent', () => {
parent: parent,
})

expect(child.stateParams).toMatchObject({
expect(child.state).toMatchObject({
foo: Number,
})
})
Expand Down
10 changes: 5 additions & 5 deletions src/services/createRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function createRoute<
const TQuery extends string | Query | undefined = undefined,
const TMeta extends RouteMeta = RouteMeta,
const TState extends Record<string, Param> = Record<string, Param>
>(options: CreateRouteOptions<TName, TPath, TQuery, TMeta> & WithHooks & WithoutComponents & WithParent<TParent> & (WithState<TState> | WithoutState)): Route<CombineKey<TParent['key'], ToKey<TName>>, Host<'', {}>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>, CombineMeta<TMeta, TParent['meta']>, CombineState<TState, TParent['stateParams']>>
>(options: CreateRouteOptions<TName, TPath, TQuery, TMeta> & WithHooks & WithoutComponents & WithParent<TParent> & (WithState<TState> | WithoutState)): Route<CombineKey<TParent['key'], ToKey<TName>>, Host<'', {}>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>, CombineMeta<TMeta, TParent['meta']>, CombineState<TState, TParent['state']>>

export function createRoute<
TComponent extends Component,
Expand All @@ -60,7 +60,7 @@ export function createRoute<
const TQuery extends string | Query | undefined = undefined,
const TMeta extends RouteMeta = RouteMeta,
const TState extends Record<string, Param> = Record<string, Param>
>(options: CreateRouteOptions<TName, TPath, TQuery, TMeta> & WithHooks & WithComponent<TComponent, RouteParams<TPath, TQuery, TParent>> & WithParent<TParent> & (WithState<TState> | WithoutState)): Route<CombineKey<TParent['key'], ToKey<TName>>, Host<'', {}>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>, CombineMeta<TMeta, TParent['meta']>, CombineState<TState, TParent['stateParams']>>
>(options: CreateRouteOptions<TName, TPath, TQuery, TMeta> & WithHooks & WithComponent<TComponent, RouteParams<TPath, TQuery, TParent>> & WithParent<TParent> & (WithState<TState> | WithoutState)): Route<CombineKey<TParent['key'], ToKey<TName>>, Host<'', {}>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>, CombineMeta<TMeta, TParent['meta']>, CombineState<TState, TParent['state']>>

export function createRoute<
TComponents extends Record<string, Component>,
Expand All @@ -79,14 +79,14 @@ export function createRoute<
const TQuery extends string | Query | undefined = undefined,
const TMeta extends RouteMeta = RouteMeta,
const TState extends Record<string, Param> = Record<string, Param>
>(options: CreateRouteOptions<TName, TPath, TQuery, TMeta> & WithHooks & WithComponents<TComponents, RouteParams<TPath, TQuery, TParent>> & WithParent<TParent> & (WithState<TState> | WithoutState)): Route<CombineKey<TParent['key'], ToKey<TName>>, Host<'', {}>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>, CombineMeta<TMeta, TParent['meta']>, CombineState<TState, TParent['stateParams']>>
>(options: CreateRouteOptions<TName, TPath, TQuery, TMeta> & WithHooks & WithComponents<TComponents, RouteParams<TPath, TQuery, TParent>> & WithParent<TParent> & (WithState<TState> | WithoutState)): Route<CombineKey<TParent['key'], ToKey<TName>>, Host<'', {}>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>, CombineMeta<TMeta, TParent['meta']>, CombineState<TState, TParent['state']>>

export function createRoute(options: CreateRouteOptions): Route {
const key = toKey(options.name)
const path = toPath(options.path)
const query = toQuery(options.query)
const meta = options.meta ?? {}
const stateParams = isWithState(options) ? options.state : {}
const state = isWithState(options) ? options.state : {}
const rawRoute = markRaw({ meta: {}, state: {}, ...options })

const route = {
Expand All @@ -96,7 +96,7 @@ export function createRoute(options: CreateRouteOptions): Route {
path,
query,
meta,
stateParams,
state,
depth: 1,
host: host('', {}),
}
Expand Down

0 comments on commit c1cf6e9

Please sign in to comment.