Skip to content

Commit

Permalink
refactor: AllActivityName -> `RegisteredActivityName
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyfromundefined committed Sep 25, 2024
1 parent 5f28bce commit dabb4c7
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 22 deletions.
4 changes: 2 additions & 2 deletions config/src/ActivityLoader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ActivityLoaderArgs } from "./ActivityLoaderArgs";
import type { AllActivityName } from "./AllActivityName";
import type { RegisteredActivityName } from "./RegisteredActivityName";

export type ActivityLoader<ActivityName extends AllActivityName> = (
export type ActivityLoader<ActivityName extends RegisteredActivityName> = (
args: ActivityLoaderArgs<ActivityName>,
) => any;
8 changes: 5 additions & 3 deletions config/src/ActivityLoaderArgs.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import type { ActivityDefinition } from "./ActivityDefinition";
import type { AllActivityName } from "./AllActivityName";
import type { Config } from "./Config";
import type { InferActivityParams } from "./InferActivityParams";
import type { RegisteredActivityName } from "./RegisteredActivityName";

export interface ActivityLoaderArgs<ActivityName extends AllActivityName> {
export interface ActivityLoaderArgs<
ActivityName extends RegisteredActivityName,
> {
params: InferActivityParams<ActivityName>;
config: Config<ActivityDefinition<AllActivityName>>;
config: Config<ActivityDefinition<RegisteredActivityName>>;
}
4 changes: 2 additions & 2 deletions config/src/InferActivityParams.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { ActivityBaseParams } from "./ActivityBaseParams";
import type { AllActivityName } from "./AllActivityName";
import type { RegisteredActivityName } from "./RegisteredActivityName";
import type { RegisteredActivityParamTypes } from "./RegisteredActivityParamTypes";

export type InferActivityParams<ActivityName extends AllActivityName> =
export type InferActivityParams<ActivityName extends RegisteredActivityName> =
RegisteredActivityParamTypes[ActivityName] extends never
? ActivityBaseParams
: RegisteredActivityParamTypes[ActivityName];
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { RegisteredActivityParamTypes } from "./RegisteredActivityParamTypes";

export type AllActivityName = Extract<
export type RegisteredActivityName = Extract<
keyof RegisteredActivityParamTypes,
string
>;
2 changes: 1 addition & 1 deletion config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ export * from "./ActivityBaseParams";
export * from "./ActivityDefinition";
export * from "./ActivityLoader";
export * from "./ActivityLoaderArgs";
export * from "./AllActivityName";
export * from "./Config";
export * from "./InferActivityParams";
export * from "./Register";
export * from "./RegisteredActivityName";
export * from "./RegisteredActivityParamTypes";
10 changes: 7 additions & 3 deletions extensions/link/src/future/Link.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/// <reference types="@stackflow/plugin-history-sync" />

import type { AllActivityName, InferActivityParams } from "@stackflow/config";
import type {
InferActivityParams,
RegisteredActivityName,
} from "@stackflow/config";
import { useConfig, useFlow } from "@stackflow/react/future";
import { useMemo } from "react";
import { omit } from "./omit";
Expand All @@ -13,15 +16,16 @@ type AnchorProps = Omit<
"ref" | "href"
>;

export interface LinkProps<K extends AllActivityName> extends AnchorProps {
export interface LinkProps<K extends RegisteredActivityName>
extends AnchorProps {
ref?: React.RefObject<HTMLAnchorElement>;
activityName: K;
activityParams: InferActivityParams<K>;
animate?: boolean;
replace?: boolean;
}

export function Link<K extends AllActivityName>(props: LinkProps<K>) {
export function Link<K extends RegisteredActivityName>(props: LinkProps<K>) {
const config = useConfig();
const { push, replace } = useFlow();

Expand Down
9 changes: 6 additions & 3 deletions integrations/react/src/future/Actions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import type { AllActivityName, InferActivityParams } from "@stackflow/config";
import type {
InferActivityParams,
RegisteredActivityName,
} from "@stackflow/config";

export type Actions = {
push<K extends AllActivityName>(
push<K extends RegisteredActivityName>(
activityName: K,
activityParams: InferActivityParams<K>,
options?: {
Expand All @@ -10,7 +13,7 @@ export type Actions = {
): {
activityId: string;
};
replace<K extends AllActivityName>(
replace<K extends RegisteredActivityName>(
activityName: K,
activityParams: InferActivityParams<K>,
options?: {
Expand Down
7 changes: 5 additions & 2 deletions integrations/react/src/future/ActivityComponentType.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type { AllActivityName, InferActivityParams } from "@stackflow/config";
import type {
InferActivityParams,
RegisteredActivityName,
} from "@stackflow/config";
import type React from "react";

export type ActivityComponentType<ActivityName extends AllActivityName> =
export type ActivityComponentType<ActivityName extends RegisteredActivityName> =
React.ComponentType<{ params: InferActivityParams<ActivityName> }>;
8 changes: 5 additions & 3 deletions integrations/react/src/future/useActivityParams.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import type {
InferActivityParams,
RegisteredActivityName,
} from "@stackflow/config";
import { useContext } from "react";

import type { AllActivityName, InferActivityParams } from "@stackflow/config";
import { ActivityContext } from "../__internal__/activity/ActivityProvider";

export function useActivityParams<
ActivityName extends AllActivityName,
ActivityName extends RegisteredActivityName,
>(): InferActivityParams<ActivityName> {
return useContext(ActivityContext)
.params as InferActivityParams<ActivityName>;
Expand Down
7 changes: 5 additions & 2 deletions integrations/react/src/future/useStepFlow.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import type { AllActivityName, InferActivityParams } from "@stackflow/config";
import type {
InferActivityParams,
RegisteredActivityName,
} from "@stackflow/config";
import { useCoreActions } from "../__internal__/core";
import type { StepActions } from "./StepActions";
import { makeStepActions } from "./makeStepActions";

export function useStepFlow<ActivityName extends AllActivityName>(
export function useStepFlow<ActivityName extends RegisteredActivityName>(
activityName: ActivityName,
): StepActions<InferActivityParams<ActivityName>> {
const coreActions = useCoreActions();
Expand Down

0 comments on commit dabb4c7

Please sign in to comment.