Skip to content

Commit

Permalink
refactor: replace index signature to record
Browse files Browse the repository at this point in the history
  • Loading branch information
SEOKKAMONI committed Jan 30, 2024
1 parent 445b523 commit bd09842
Show file tree
Hide file tree
Showing 20 changed files with 33 additions and 69 deletions.
8 changes: 2 additions & 6 deletions core/src/Stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ export type ActivityTransitionState =

export type ActivityStep = {
id: string;
params: {
[key: string]: string | undefined;
};
params: Record<string, string | undefined>;
enteredBy: PushedEvent | ReplacedEvent | StepPushedEvent | StepReplacedEvent;
exitedBy?: ReplacedEvent | PoppedEvent | StepReplacedEvent | StepPoppedEvent;
};
Expand All @@ -25,9 +23,7 @@ export type Activity = {
id: string;
name: string;
transitionState: ActivityTransitionState;
params: {
[key: string]: string | undefined;
};
params: Record<string, string | undefined>;
context?: {};
enteredBy: PushedEvent | ReplacedEvent;
exitedBy?: ReplacedEvent | PoppedEvent;
Expand Down
7 changes: 1 addition & 6 deletions core/src/event-types/ActivityRegisteredEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ export type ActivityRegisteredEvent = BaseDomainEvent<
activityName: string;
activityParamsSchema?: {
type: "object";
properties: {
[key: string]: {
type: "string";
enum?: string[];
};
};
properties: Record<string, { type: "string"; enum?: string[] }>;
required: string[];
};
}
Expand Down
4 changes: 1 addition & 3 deletions core/src/event-types/PushedEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ export type PushedEvent = BaseDomainEvent<
{
activityId: string;
activityName: string;
activityParams: {
[key: string]: string | undefined;
};
activityParams: Record<string, string | undefined>;
skipEnterActiveState?: boolean;
activityContext?: {};
}
Expand Down
4 changes: 1 addition & 3 deletions core/src/event-types/ReplacedEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ export type ReplacedEvent = BaseDomainEvent<
{
activityId: string;
activityName: string;
activityParams: {
[key: string]: string | undefined;
};
activityParams: Record<string, string | undefined>;
skipEnterActiveState?: boolean;
activityContext?: {};
}
Expand Down
4 changes: 1 addition & 3 deletions core/src/event-types/StepPushedEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ export type StepPushedEvent = BaseDomainEvent<
"StepPushed",
{
stepId: string;
stepParams: {
[key: string]: string | undefined;
};
stepParams: Record<string, string | undefined>;
}
>;
4 changes: 1 addition & 3 deletions core/src/event-types/StepReplacedEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ export type StepReplacedEvent = BaseDomainEvent<
"StepReplaced",
{
stepId: string;
stepParams: {
[key: string]: string | undefined;
};
stepParams: Record<string, string | undefined>;
}
>;
4 changes: 1 addition & 3 deletions extensions/compat-await-push/src/resolveMap.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
export const resolveMap: {
[key: string]: (value: unknown) => void;
} = {};
export const resolveMap: Record<string, (value: unknown) => void> = {};
2 changes: 1 addition & 1 deletion extensions/link/src/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type LinkProps<K, P> = {
urlPatternOptions?: UrlPatternOptions;
} & AnchorProps;

export type TypeLink<T extends { [activityName: string]: unknown } = {}> = <
export type TypeLink<T extends Record<string, unknown> = {}> = <
K extends Extract<keyof T, string>,
>(
props: LinkProps<K, T[K] extends ActivityComponentType<infer U> ? U : never>,
Expand Down
4 changes: 1 addition & 3 deletions extensions/link/src/createLinkComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import type { TypeLink } from "./Link";
import { Link } from "./Link";

export function createLinkComponent<
T extends { [activityName: string]: unknown },
>(): {
export function createLinkComponent<T extends Record<string, unknown>>(): {
Link: TypeLink<T>;
} {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ export type GoogleAnalyticsPluginOptions = {
};
};

export function googleAnalyticsPlugin<
T extends { [activityName: string]: unknown },
>({
export function googleAnalyticsPlugin<T extends Record<string, unknown>>({
trackingId,
userInfo,
useTitle = false,
Expand Down
6 changes: 3 additions & 3 deletions extensions/plugin-history-sync/src/makeTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function pathToUrl(path: string) {
}

function urlSearchParamsToMap(urlSearchParams: URLSearchParams) {
const map: { [key: string]: any } = {};
const map: Record<string, any> = {};

urlSearchParams.forEach((value, key) => {
map[key] = value;
Expand Down Expand Up @@ -50,7 +50,7 @@ export function makeTemplate(
const pattern = new UrlPattern(`${templateStr}(/)`, urlPatternOptions);

return {
fill(params: { [key: string]: string | undefined }) {
fill(params: Record<string, string | undefined>) {
const pathname = pattern.stringify(params);
const pathParams = pattern.match(pathname);

Expand Down Expand Up @@ -79,7 +79,7 @@ export function makeTemplate(
prependQuestionMarkInSearchParams(searchParams)
);
},
parse<T extends { [key: string]: string | undefined }>(
parse<T extends Record<string, string | undefined>>(
path: string,
): T | null {
const url = pathToUrl(path);
Expand Down
5 changes: 1 addition & 4 deletions extensions/plugin-preload/src/LoadersContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import { createContext, useContext } from "react";

import type { Loader } from "./Loader";

export type LoadersMap = {
[activityName in string]?: Loader;
};

export type LoadersMap = Record<string, Loader | undefined>;
export const LoadersContext = createContext<LoadersMap>({});

interface LoadersProviderProps {
Expand Down
4 changes: 1 addition & 3 deletions extensions/plugin-preload/src/createPreloader.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import type { PreloadFunc } from "./usePreloader";
import { usePreloader } from "./usePreloader";

export function createPreloader<
T extends { [activityName: string]: unknown },
>(): {
export function createPreloader<T extends Record<string, unknown>>(): {
usePreloader: () => { preload: PreloadFunc<T> };
} {
return {
Expand Down
6 changes: 2 additions & 4 deletions extensions/plugin-preload/src/pluginPreload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import type {
import type { Loader } from "./Loader";
import { LoadersProvider } from "./LoadersContext";

export type PreloadPluginOptions<
T extends { [activityName: string]: unknown },
> = {
export type PreloadPluginOptions<T extends Record<string, unknown>> = {
loaders: {
[key in Extract<keyof T, string>]?: T[key] extends ActivityComponentType<
infer U
Expand All @@ -18,7 +16,7 @@ export type PreloadPluginOptions<
};
};

export function preloadPlugin<T extends { [activityName: string]: unknown }>(
export function preloadPlugin<T extends Record<string, unknown>>(
options: PreloadPluginOptions<T>,
): StackflowReactPlugin<T> {
return () => ({
Expand Down
20 changes: 10 additions & 10 deletions integrations/react/src/BaseActivities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import type { ActivityRegisteredEvent } from "@stackflow/core";

import type { ActivityComponentType } from "./activity";

export type BaseActivities = {
[activityName: string]:
| ActivityComponentType<any>
| {
component: ActivityComponentType<any>;
paramsSchema: NonNullable<
ActivityRegisteredEvent["activityParamsSchema"]
>;
};
};
export type BaseActivities = Record<
string,
| ActivityComponentType<any>
| {
component: ActivityComponentType<any>;
paramsSchema: NonNullable<
ActivityRegisteredEvent["activityParamsSchema"]
>;
}
>;
4 changes: 1 addition & 3 deletions integrations/react/src/MainRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import { usePlugins } from "./plugins";
import type { WithRequired } from "./utils";

interface MainRendererProps {
activityComponentMap: {
[key: string]: ActivityComponentType;
};
activityComponentMap: Record<string, ActivityComponentType>;
initialContext: any;
}
const MainRenderer: React.FC<MainRendererProps> = ({
Expand Down
4 changes: 1 addition & 3 deletions integrations/react/src/PluginRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import type { StackflowReactPlugin } from "./StackflowReactPlugin";
import type { WithRequired } from "./utils";

interface PluginRendererProps {
activityComponentMap: {
[key: string]: ActivityComponentType;
};
activityComponentMap: Record<string, ActivityComponentType>;
plugin: WithRequired<ReturnType<StackflowReactPlugin>, "render">;
initialContext: any;
}
Expand Down
2 changes: 1 addition & 1 deletion integrations/react/src/activity/ActivityComponentType.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export type ActivityComponentType<
T extends { [K in keyof T]: string | undefined } = {},
T extends Record<keyof T, string | undefined> = {},
> = React.ComponentType<{ params: T }>;
2 changes: 1 addition & 1 deletion integrations/react/src/activity/useActivityParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ActivityContext } from "./ActivityProvider";
* Get current activity parameters
*/
export function useActivityParams<
T extends { [key in keyof T]: string | undefined },
T extends Record<keyof T, string | undefined>,
>(): T {
return useContext(ActivityContext).params as T;
}
4 changes: 1 addition & 3 deletions integrations/react/src/stackflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ export function stackflow<T extends BaseActivities>(
[key]:
"component" in Activity ? memo(Activity.component) : memo(Activity),
}),
{} as {
[key: string]: ActivityComponentType;
},
{} as Record<string, ActivityComponentType>,
);

const enoughPastTime = () =>
Expand Down

0 comments on commit bd09842

Please sign in to comment.