Skip to content

Commit

Permalink
update signature
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyfromundefined committed Jan 20, 2025
1 parent 447022b commit 3d6563a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import { createContext } from "react";
import type { ActivityComponentType } from "../stable";

type Value = {
activityComponentMap: { [key: string]: ActivityComponentType<any> };
set: (key: string, value: ActivityComponentType<any>) => void;
activityComponentMap: { [activityName: string]: ActivityComponentType<any> };
setActivityComponentMap: (args: {
activityName: string;
Component: ActivityComponentType<any>;
}) => void;
};

export const UNSAFE_ActivityComponentMapContext = createContext<Value>(
Expand Down
25 changes: 13 additions & 12 deletions integrations/react/src/future/stackflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
makeCoreStore,
makeEvent,
} from "@stackflow/core";
import React, { useMemo, useState } from "react";
import React, { useMemo, useReducer } from "react";
import MainRenderer from "../__internal__/MainRenderer";
import { makeActivityId } from "../__internal__/activity";
import { CoreProvider } from "../__internal__/core";
Expand Down Expand Up @@ -155,21 +155,22 @@ export function stackflow<
return store;
}, []);

const [activityComponentMap, setActivityComponentMap] = useState(
() => input.components,
const [activityComponentMap, setActivityComponentMap] = useReducer<
React.Reducer<
{ [activityName: string]: ActivityComponentType<any> },
{ activityName: string; Component: ActivityComponentType<any> }
>
>(
(map, { activityName, Component }) => ({
...map,
[activityName]: Component,
}),
input.components,
);

return (
<ActivityComponentMapProvider
value={{
activityComponentMap,
set(key, value) {
setActivityComponentMap((map) => ({
...map,
[key]: value,
}));
},
}}
value={{ activityComponentMap, setActivityComponentMap }}
>
<ConfigProvider value={input.config}>
<PluginsProvider value={coreStore.pluginInstances}>
Expand Down

0 comments on commit 3d6563a

Please sign in to comment.