Skip to content

Commit

Permalink
리뷰 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyfromundefined committed Jan 15, 2025
1 parent 761b26d commit 0a20f4f
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 27 deletions.
6 changes: 4 additions & 2 deletions integrations/react/src/__internal__/ActivityComponentType.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type React from "react";
import type { LazyActivityComponentType } from "./LazyActivityComponentType";
import type { StaticActivityComponentType } from "./StaticActivityComponentType";

export type ActivityComponentType<T extends { [K in keyof T]: any } = {}> =
React.ComponentType<{ params: T }>;
| StaticActivityComponentType<T>
| LazyActivityComponentType<T>;
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { ActivityComponentType } from "./ActivityComponentType";
import type { StaticActivityComponentType } from "./StaticActivityComponentType";

export type LazyActivityComponentType<T extends { [K in keyof T]: any } = {}> =
React.LazyExoticComponent<ActivityComponentType<T>> & {
React.LazyExoticComponent<StaticActivityComponentType<T>> & {
_stackflow?: {
type: "lazy";
load: () => Promise<{ default: ActivityComponentType<T> }>;
load: () => Promise<{ default: StaticActivityComponentType<T> }>;
};
};
3 changes: 1 addition & 2 deletions integrations/react/src/__internal__/MainRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useEffect } from "react";
import type { ActivityComponentType } from "./ActivityComponentType";
import type { LazyActivityComponentType } from "./LazyActivityComponentType";
import PluginRenderer from "./PluginRenderer";
import { useCoreState } from "./core";
import { usePlugins } from "./plugins";
Expand All @@ -9,7 +8,7 @@ import type { WithRequired } from "./utils";

interface MainRendererProps {
activityComponentMap: {
[key: string]: ActivityComponentType | LazyActivityComponentType;
[key: string]: ActivityComponentType;
};
initialContext: any;
}
Expand Down
3 changes: 1 addition & 2 deletions integrations/react/src/__internal__/PluginRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type React from "react";
import type { ActivityComponentType } from "./ActivityComponentType";
import type { LazyActivityComponentType } from "./LazyActivityComponentType";
import type { StackflowReactPlugin } from "./StackflowReactPlugin";
import { ActivityProvider } from "./activity";
import { useCoreState } from "./core";
Expand All @@ -9,7 +8,7 @@ import type { WithRequired } from "./utils";

interface PluginRendererProps {
activityComponentMap: {
[key: string]: ActivityComponentType | LazyActivityComponentType;
[key: string]: ActivityComponentType;
};
plugin: WithRequired<ReturnType<StackflowReactPlugin>, "render">;
initialContext: any;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type React from "react";

export type StaticActivityComponentType<
T extends { [K in keyof T]: any } = {},
> = React.ComponentType<{ params: T }>;
12 changes: 6 additions & 6 deletions integrations/react/src/future/lazy.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from "react";
import type { ActivityComponentType } from "../__internal__/ActivityComponentType";
import type { LazyActivityComponentType } from "../__internal__/LazyActivityComponentType";
import type { StaticActivityComponentType } from "../__internal__/StaticActivityComponentType";

export function lazy<T extends { [K in keyof T]: any } = {}>(
load: () => Promise<{ default: ActivityComponentType<T> }>,
load: () => Promise<{ default: StaticActivityComponentType<T> }>,
): LazyActivityComponentType<T> {
let cachedValue: { default: ActivityComponentType<T> } | null = null;
let cachedValue: { default: StaticActivityComponentType<T> } | null = null;

const cachedLoad = async () => {
if (!cachedValue) {
Expand All @@ -15,8 +15,8 @@ export function lazy<T extends { [K in keyof T]: any } = {}>(
return cachedValue;
};

const DynamicComponent: LazyActivityComponentType<T> = React.lazy(cachedLoad);
DynamicComponent._stackflow = { type: "lazy", load: cachedLoad };
const LazyComponent: LazyActivityComponentType<T> = React.lazy(cachedLoad);
LazyComponent._stackflow = { type: "lazy", load: cachedLoad };

return DynamicComponent;
return LazyComponent;
}
7 changes: 2 additions & 5 deletions integrations/react/src/future/loader/loaderPlugin.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import type { ActivityDefinition } from "@stackflow/config";
import type { ActivityComponentType } from "../../__internal__/ActivityComponentType";
import type { LazyActivityComponentType } from "../../__internal__/LazyActivityComponentType";
import type { StackflowReactPlugin } from "../../__internal__/StackflowReactPlugin";
import type { StackflowInput } from "../stackflow";

export function loaderPlugin<
T extends ActivityDefinition<string>,
R extends {
[activityName in T["name"]]:
| ActivityComponentType<any>
| LazyActivityComponentType<any>;
[activityName in T["name"]]: ActivityComponentType<any>;
},
>(input: StackflowInput<T, R>): StackflowReactPlugin {
return () => ({
Expand Down Expand Up @@ -62,7 +59,7 @@ export function loaderPlugin<
},
onBeforePush({
actionParams,
actions: { overrideActionParams, dispatchEvent, pause, resume },
actions: { overrideActionParams, pause, resume },
}) {
const { activityName, activityParams, activityContext } = actionParams;

Expand Down
9 changes: 2 additions & 7 deletions integrations/react/src/future/stackflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
} from "@stackflow/core";
import React, { useMemo } from "react";
import type { ActivityComponentType } from "../__internal__/ActivityComponentType";
import type { LazyActivityComponentType } from "../__internal__/LazyActivityComponentType";
import MainRenderer from "../__internal__/MainRenderer";
import { makeActivityId } from "../__internal__/activity";
import { CoreProvider } from "../__internal__/core";
Expand All @@ -33,9 +32,7 @@ export type StackflowPluginsEntry =
export type StackflowInput<
T extends ActivityDefinition<string>,
R extends {
[activityName in T["name"]]:
| ActivityComponentType<any>
| LazyActivityComponentType<any>;
[activityName in T["name"]]: ActivityComponentType<any>;
},
> = {
config: Config<T>;
Expand All @@ -52,9 +49,7 @@ export type StackflowOutput = {
export function stackflow<
T extends ActivityDefinition<string>,
R extends {
[activityName in T["name"]]:
| ActivityComponentType<any>
| LazyActivityComponentType<any>;
[activityName in T["name"]]: ActivityComponentType<any>;
},
>(input: StackflowInput<T, R>): StackflowOutput {
const plugins = [
Expand Down

0 comments on commit 0a20f4f

Please sign in to comment.